|
Steps to configure Android SDK
Step 1 - Setup Java Development Kit (JDK): You can download the latest version of Java JDK from Oracle's Java site
Step 2 - Setup Android SDK: You can download the latest version of Android SDK from Android official website
Step 3 - Setup Eclipse IDE
Step 4 - Setup Android Development Tools (ADT) Plugin
Step 5 - Create Android Virtual Device
|
|
|
|
|
When I run my app in Android Studio I get the message "Unfortunately your App Appointment DB has stopped working". Not sure how to resolve this issue. Here is my code.
MainActivity.java
package com.example.android.appointmentdb;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
TextView idView;
EditText clientNameBox;
EditText clientPhoneBox;
EditText clientTimeBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
idView = (TextView) findViewById(R.id.clientID);
clientNameBox = (EditText) findViewById(R.id.clientName);
clientPhoneBox =(EditText) findViewById(R.id.clientPhone);
clientTimeBox =(EditText) findViewById(R.id.clientTime);
}
public void newClient (View view) {
MyDBHandler dbHandler = new MyDBHandler(this, null, null, 1);
String phone = clientPhoneBox.getText().toString();
String name = clientNameBox.getText().toString();
String time = clientTimeBox.getText().toString();
Appointment newAppointment = new Appointment(name, phone, time);
dbHandler.addClient(newAppointment);
Toast.makeText(getApplicationContext(), "Your appointment is set =)",
Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
MyDBHandler.java
package com.example.android.appointmentdb;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
public class MyDBHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "thursdayDB.db";
private static final String TABLE_APPOINTMENTS = "7-16-2015";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_CLIENTNAME = "clientname";
public static final String COLUMN_CLIENTPHONE = "clientphone";
public static final String COLUMN_CLIENTTIME = "clienttime";
public MyDBHandler(Context context, String name,
SQLiteDatabase.CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_PRODUCTS_TABLE = "CREATE TABLE " +
TABLE_APPOINTMENTS + "("
+ COLUMN_ID + " INTEGER PRIMARY KEY,"
+ COLUMN_CLIENTNAME+ " TEXT,"
+ COLUMN_CLIENTPHONE + " TEXT,"
+ COLUMN_CLIENTTIME + " TEXT" + ")";
db.execSQL(CREATE_PRODUCTS_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_APPOINTMENTS);
onCreate(db);
}
public void addClient(Appointment appointment) {
ContentValues values = new ContentValues();
values.put(COLUMN_CLIENTNAME, appointment.getClientName());
values.put(COLUMN_CLIENTPHONE, appointment.getClientPhone());
values.put(COLUMN_CLIENTTIME, appointment.getClientTime());
SQLiteDatabase db = this.getWritableDatabase();
db.insert(TABLE_APPOINTMENTS, null, values);
db.close();
}
public Appointment findAppointment(String clientname) {
String query = "Select * FROM " + TABLE_APPOINTMENTS + " WHERE " + COLUMN_CLIENTNAME + " = \"" + clientname + "\"";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
Appointment appointment = new Appointment();
if (cursor.moveToFirst()) {
cursor.moveToFirst();
appointment.setID(Integer.parseInt(cursor.getString(0)));
appointment.setClientName(cursor.getString(1));
appointment.setClientPhone(cursor.getString(2));
appointment.setClientTime(cursor.getString(3));
cursor.close();
} else {
appointment = null;
}
db.close();
return appointment;
}
}
Appointment.java
package com.example.android.appointmentdb;
public class Appointment {
private int _id;
private String _clientName;
private String _clientPhone;
private String _clientTime;
public Appointment() {
}
public Appointment(int id, String clientName, String clientPhone, String clientTime) {
this._id = id;
this._clientName = clientName;
this._clientPhone = clientPhone;
this._clientTime = clientTime;
}
public Appointment(String clientName, String clientPhone, String clientTime) {
this._clientName = clientName;
this._clientPhone = clientPhone;
this._clientTime = clientTime;
}
public void setID(int id) {
this._id = id;
}
public int getID() {
return this._id;
}
public void setClientName(String clientName) {
this._clientName = clientName;
}
public String getClientName() {
return this._clientName;
}
public void setClientTime(String clientTime) {
this._clientTime = clientTime;
}
public String getClientTime() {
return this._clientTime;
}
public void setClientPhone(String clientPhone) {
this._clientPhone = clientPhone;
}
public String getClientPhone() {
return this._clientPhone;
}
}
activity_main.xml
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/id_string"
android:id="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=""
android:id="@+id/clientID" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/name_string"
android:id="@+id/textView3" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/clientName" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/phone_string"
android:id="@+id/textView2" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="@+id/clientPhone" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/time_string"
android:id="@+id/textView1" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="@+id/clientTime" />
</TableRow>
</TableLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_margin="10dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/book_string"
android:id="@+id/button"
android:onClick="newClient"/>
</LinearLayout>
</LinearLayout>
|
|
|
|
|
Please do not just dump all your code and expect someone to debug it for you. Look at the Logcat messages to see where it crashed and what errors are reported. You can then narrow it down to see what part of your code is causing the problem, and how you can add some more code to help diagnose it.
|
|
|
|
|
I'm a beginner and wasn't able to figure out how to read log cat error messages and debug. Just looking for help not sarcasm. Thought someone might be able to easily identify the error. I'll figure it out on my own. Thanks anyway.
|
|
|
|
|
Member 11855170 wrote: Just looking for help not sarcasm. Help is what I offered you.
Member 11855170 wrote: Thought someone might be able to easily identify the error. Well we probably could have done if you had presented it to us. All you have provided is a listing of your program with no context, so we have no idea where to start looking. If you wish to become a developer then you need to spend some time getting familiar with the debugging tools in your armoury. Without them you will find things very difficult.
modified 23-Jul-15 3:49am.
|
|
|
|
|
Ok. I'll learn how to use the debugging tools. Any good tutorials? I'm using Android Studio.
|
|
|
|
|
|
Set a breakpoint in your activity's onCreate() method and single step through it using the debugger.
You could also remove all unnecessary code, leaving just enough for the app to run. Then start adding code back in until the problem reappears.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
i want to print the litview music data to download file in the top of the listview online data can be display in below the download file please answer me.
package com.example.fununlimitedcopy;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.jar.Attributes.Name;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.OnScanCompletedListener;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
@SuppressLint("ViewHolder")
public class Tab1 extends Fragment implements OnClickListener,OnSeekBarChangeListener
{
private static final String TAG = null;
ListView list;
CustomAdaptor1 adapter;
private Tab1 activity;
public ArrayList<listmodel> CustomListViewValuesArr = new ArrayList<listmodel>();
private ArrayList<song> songList;
MediaPlayer mPlayer;
static Context ctx;
SeekBar seek_bar;
TextView start;
TextView total;
Button audio1;
Button gif1;
Button previous;
Button next;
Button playpause;
Handler seekHandler = new Handler();
int currentsongindex = 0;
Song songInfo = null;
int selPosition = -1;
int a = 1, b = 1;
boolean fristplay = false;
String activitystate = "empty";
ArrayList<musicdata> arrSongList; // three filds are show.
private static String folderPath = "";
String songpath;
String musicurl = "http://exporterp.in/vm/songs/";
int count;
String fileOutput;
ArrayList<string> sdcard = null;
boolean btndisplay;
boolean posting;
AlertDialog alertDialog ;
String StorePath;
public Tab1(Context c)
{
// TODO Auto-generated constructor stub.
ctx = c;
}
@Override
public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.tab_1, container, false);
songpath = Environment.getExternalStorageDirectory().getPath() + "/" + getResources().getString(R.string.app_download) + "/music";
// songList = new ArrayList<song>();
// getSongList();
Resources res = getResources();
list = (ListView) v.findViewById(R.id.list);
adapter = new CustomAdaptor1();
arrSongList = new ArrayList<musicdata>();
list.setAdapter(adapter);
seek_bar = (SeekBar) v.findViewById(R.id.songseekbar);
start = (TextView) v.findViewById(R.id.currentduration);
total = (TextView) v.findViewById(R.id.totalduration);
previous = (Button) v.findViewById(R.id.btnpreplay);
next = (Button) v.findViewById(R.id.btnnextplay);
playpause = (Button) v.findViewById(R.id.playpausesong);
previous.setOnClickListener(this);
playpause.setOnClickListener(this);
next.setOnClickListener(this);
seek_bar.setOnSeekBarChangeListener(this);
// Toast.makeText(ctx, songList.size() + "", 100).show();
countaudio();
if(Utils.isInternetConnected(ctx))
{
new load_media_from_url().execute();
}
else
{
alertDialog = new AlertDialog.Builder(ctx).create();
alertDialog.setTitle("! Connection");
alertDialog.setMessage("You Must Have Connected in Internet!!!");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});
alertDialog.show();
}
PhoneStateListener phoneStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
}
}
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
if (mPlayer != null) {
if (!mPlayer.isPlaying()) {
mPlayer.start();
}
}
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
}
}
}
super.onCallStateChanged(state, incomingNumber);
}
};
TelephonyManager mgr = (TelephonyManager) getActivity()
.getSystemService(Context.TELEPHONY_SERVICE);
if (mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
return v;
}
public void playknow()
{
// songInfo = (Song) songList.get(currentsongindex);
// String path = songInfo.getAudioPath();
// callMediaPlay(path, true);
String list11 = arrSongList.get(currentsongindex).path;
Toast.makeText(ctx, list11, 2000);
callMediaPlay(list11, true);
playpause.setBackgroundResource(R.drawable.play_pause_press);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
}
private void setAudio(int currentsongindex2)
{
// TODO Auto-generated method stub
// songInfo = (Song) songList.get(currentsongindex2);
// Toast.makeText(ctx, songInfo.getAudioPath() + "",
// Toast.LENGTH_LONG).show();
try {
mPlayer.setDataSource(songInfo.getAudioPath());
mPlayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Runnable run = new Runnable() {
@Override
public void run() {
seekUpdation();
}
};
public void seekUpdation() {
if (mPlayer != null && mPlayer.isPlaying()) {
seek_bar.setProgress(mPlayer.getCurrentPosition());
seekHandler.postDelayed(run, 1000);
start.setText(timetraceed(mPlayer.getCurrentPosition()));
}
}
public String timetraceed(long getduration) {
long minute = ((getduration / 1000) / 60);
long second;
if (mPlayer.getDuration() < 60000) {
second = getduration / 1000;
} else {
second = ((getduration / 1000) % 60);
}
String s = minute + ":" + second;
return s;
}
// --------------------------count for song in music folder----------------------------------------------
public void countaudio() {
sdcard = new ArrayList<string>();
File f = new File(Environment.getExternalStorageDirectory().getPath()
+ "/" + getResources().getString(R.string.app_download)
+ "/music");
File[] dirFiles = f.listFiles();
Toast.makeText(ctx, dirFiles.length+"", 5000).show();
if (dirFiles.length != 0)
{
// loops through the array of files, outputing the name to console
for (int ii = 0; ii < dirFiles.length; ii++)
{
fileOutput = dirFiles[ii].toString();
fileOutput = fileOutput
.substring(fileOutput.lastIndexOf("/") + 1);
sdcard.add(fileOutput.replace(".mp3", ""));
MusicData obj = new MusicData();
obj.name = fileOutput.replace(".mp3", "");
obj.path = f.getAbsolutePath() + "/" + fileOutput;
obj.isDownload = false;
arrSongList.add(obj);
// Toast.makeText(ctx, fileOutput+"", 7000).show();
}
// sdcard = new ArrayList<string>(Arrays.asList(fileOutput));
//Toast.makeText(ctx, sdcard + "", 3000).show();
adapter.addAll(sdcard);
Toast.makeText(ctx, sdcard + "", 3000).show();
list.setAdapter(adapter);
}
}
private void getSongList() {
// TODO Auto-generated method stub
ContentResolver musicResolver = ctx.getContentResolver();
Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = ctx.getContentResolver().query(musicUri, null,
null, null, null);
if (musicCursor != null && musicCursor.moveToFirst()) {
// get columns.....
int titleColumn = musicCursor
.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor
.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor
.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
int audiopath = musicCursor
.getColumnIndex(android.provider.MediaStore.Audio.Media.DATA);
// add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String thisaudiopath = musicCursor.getString(audiopath);
// songList.add(new Song(thisId, thisTitle,
// thisArtist,thisaudiopath));
} while (musicCursor.moveToNext());
}
}
// MediaPlayer mPlayer;
public void play() {
if (mPlayer != null) {
if (mPlayer.isPlaying())
mPlayer.pause();
else
mPlayer.start();
}
}
public void callMediaPlay(String path, boolean resume) {
if (mPlayer != null) {
if (mPlayer.isPlaying())
seekHandler.removeCallbacks(run);
mPlayer.stop();
mPlayer = null;
}
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// when song is prepare then the load_media_from_url are call.
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
// TODO Auto-generated method stub
// new load_media_from_url().execute();
}
});
// Toast.makeText(ctx, musicurl+"/"+path, 20000).show();
try {
mPlayer.setDataSource(path);
// Toast.makeText(ctx, musicurl+"/"+path, 2000).show();
mPlayer.prepare();
mPlayer.start();
seek_bar.setMax(mPlayer.getDuration());
seekHandler.postDelayed(run, 1000);
total.setText(timetraceed(mPlayer.getDuration()));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx,
"setdatasource You might not set the URI correctly!",
Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx,
"setdatasource You might not set the URI correctly!",
Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx,
"setdatasource You might not set the URI correctly!",
Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(ctx,
"setdatasource You might not set the URI correctly!",
Toast.LENGTH_LONG).show();
}
// try {
// mPlayer.prepare();
// } catch (IllegalStateException e) {
// Toast.makeText(ctx, "prepare You might not set the URI correctly!",
// Toast.LENGTH_LONG).show();
// } catch (IOException e) {
// Toast.makeText(ctx, "prepare You might not set the URI correctly!",
// Toast.LENGTH_LONG).show();
// }
}
public void completeplaystop() {
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mPlayer) {
// TODO Auto-generated method stub
mPlayer.stop();
}
});
}
@Override
public void onStop() {
super.onStop();
if (mPlayer != null) {
if (mPlayer.isPlaying())
mPlayer.stop();
mPlayer = null;
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub.
if (v == next) {
if (fristplay == false) {
playknow();
fristplay = true;
} else if (currentsongindex < (arrSongList.size() - 1)) {
currentsongindex = currentsongindex + 1;
// songInfo = (Song) songList.get(currentsongindex);
// String path = songInfo.getAudioPath();
// callMediaPlay(path, true);
String list11 = arrSongList.get(currentsongindex).path;
Toast.makeText(ctx, list11, 2000);
callMediaPlay(list11, true);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
}
} else if (v == previous) {
if (fristplay == false) {
// new load_media_from_url().execute();
playknow();
fristplay = true;
} else if (currentsongindex > 0) {
// new load_media_from_url().execute();
currentsongindex = currentsongindex - 1;
// songInfo = (Song) songList.get(currentsongindex);
// String path = songInfo.getAudioPath();
// callMediaPlay(path, true);
String list11 = arrSongList.get(currentsongindex).path;
Toast.makeText(ctx, list11, 2000);
callMediaPlay(list11, true);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
}
} else if (v == playpause) {
if (fristplay == false) {
// new load_media_from_url().execute();
playknow();
fristplay = true;
} else if (a == 0 && currentsongindex == 0) {
// songInfo = (Song) songList.get(currentsongindex);
// String path = songInfo.getAudioPath();
// callMediaPlay(path, true);
String list11 = arrSongList.get(currentsongindex).path;
Toast.makeText(ctx, list11, 2000);
// callMediaPlay(list11, true);
completeplaystop();
playpause.setBackgroundResource(R.drawable.play_pause_press);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
a++;
} else if (a != 0 && mPlayer != null) {
if (mPlayer.isPlaying()) {
// Toast.makeText(ctx, "hello how are you ", 1000).show();
mPlayer.pause();
seekHandler.removeCallbacks(run);
playpause.setBackgroundResource(R.drawable.play_press);
selPosition = -1;
adapter.notifyDataSetChanged();
a = 0;
}
} else if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
seekHandler.removeCallbacks(run);
playpause.setBackgroundResource(R.drawable.play_press);
final Button btnplay = (Button) v
.findViewById(R.id.btnplay);
selPosition = -1;
adapter.notifyDataSetChanged();
} else {
mPlayer.start();
seekHandler.postDelayed(run, 1000);
playpause
.setBackgroundResource(R.drawable.play_pause_press);
final Button btnplay = (Button) v
.findViewById(R.id.btnplay);
selPosition = currentsongindex;
adapter.notifyDataSetChanged();
}
}
}
}
// for tab sliding to this code will be used...
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (this.isVisible())
{
// If we are becoming invisible, then...
if (!isVisibleToUser) {
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
posting=true;
}
}
}
else
{
if(posting==true)
{
mPlayer.start();
seekHandler.postDelayed(run, 1000);
}
}
}
}
@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
// TODO Auto-generated method stub
mPlayer.seekTo(arg1);
arg0.setProgress(arg1);
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
// ========================================================custom_adapter=============================================
public class CustomAdaptor1 extends BaseAdapter {
int a = 1;
@Override
public int getCount()
{
// TODO Auto-generated method stub
return arrSongList.size();
}
@Override
public Object getItem(int position)
{
// TODO Auto-generated method stub
return arrSongList.get(position);
}
@Override
public long getItemId(int position)
{
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View v, ViewGroup parent)
{
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.custom_row, null);
//Toast.makeText(ctx, ""+arrSongList.get(position), 7000).show();
// songInfo = (Song) songList.get(position);
TextView txtSongName = (TextView) v.findViewById(R.id.txtsongtitle);
final Button btnplay = (Button) v.findViewById(R.id.btnplay);
Button btndownload = (Button) v.findViewById(R.id.btndownload);
Button btnshare = (Button) v.findViewById(R.id.btnshare);
btnplay.setTag(position + "");
txtSongName.setText(arrSongList.get(position).name);
String Url = Environment.getExternalStorageDirectory().getPath()+ "/" + getResources().getString(R.string.app_download)+ "/music";
File f = new File(Url + "/" + arrSongList.get(position));
if (!arrSongList.get(position).isDownload)
{
btndownload.setVisibility(View.GONE);
btndisplay = true;
// arrSongList.set(0,arrSongList.get(position));
// adapter.notifyDataSetChanged();
// notifyDataSetChanged();
}
btnplay.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
if (position == selPosition)
{
if (a == 1)
{
// TODO Auto-generated method stub...
// songInfo = (Song) songList.get(position);
// String path = songInfo.getAudioPath();
// Toast.makeText(ctx, a+"", 2000).show();
String list11 = arrSongList.get(position).path;
callMediaPlay(list11, true);
completeplaystop();
selPosition = position;
// notifyDataSetChanged();
playpause.setBackgroundResource(R.drawable.play_pause_press);
a++;
} else {
// Toast.makeText(ctx, "presssed", 2000).show();
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
selPosition = -1;
// notifyDataSetChanged();
playpause
.setBackgroundResource(R.drawable.play_press);
a = 1;
}
}
}
} else {
// songInfo = (Song) songList.get(position);
// String path = songInfo.getAudioPath();
// Toast.makeText(ctx, a+"", 2000).show();
String list11 = arrSongList.get(position).path;
callMediaPlay(list11, true);
completeplaystop();
selPosition = position;
// notifyDataSetChanged();
playpause
.setBackgroundResource(R.drawable.play_pause_press);
a++;
}
currentsongindex = position;
notifyDataSetChanged();
}
});
if (selPosition == position) {
btnplay.setBackgroundResource(R.drawable.pause_btn);
} else {
btnplay.setBackgroundResource(R.drawable.play_btn);
}
btnshare.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
// songInfo = (Song) songList.get(position);
// String path = songInfo.getAudioPath();
if (!arrSongList.get(position).isDownload)
{
String list11 = "file://"
+ arrSongList.get(position).path;
// Toast.makeText(ctx, list11, 5000).show();
// String mypath = songpath+list11;
sharit(list11);
}
else
{
Toast.makeText(ctx, "required code...", 3000).show();
}
}
});
btndownload.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// File wallpaperDirectory = new File("/sdcard/Wallpaper/");
// wallpaperDirectory.mkdirs();
String mypath1 = arrSongList.get(position).name;
Toast.makeText(ctx, mypath1 + "", 5000).show();
downloadMusic(mypath1, position);
// Toast.makeText(ctx,arrSongList.get(position) +"",
// 2000).show();
// File outputFile = new File(wallpaperDirectory, filename);
// FileOutputStream fos = new FileOutputStream(outputFile);
}
});
return v;
}
private void sharit(String path)
{
Uri uri = Uri.parse(path);
Intent sharingintent = new Intent(
android.content.Intent.ACTION_SEND);
sharingintent.setType("audio/*");
sharingintent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingintent,"SHARE AUDIO FILE"));
if (mPlayer != null) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
}
}
}
public void addAll(ArrayList<string> arrList)
{
// TODO Auto-generated method stub
}
}
@Override
public void onPause()
{
// TODO Auto-generated method stub
super.onPause();
activitystate = "pause";
selPosition = -1;
if (adapter != null)
adapter.notifyDataSetChanged();
playpause.setBackgroundResource(R.drawable.play_press);
}
@Override
public void onResume()
{
// TODO Auto-generated method stub
super.onResume();
if (activitystate.equals("pause"))
{
if (mPlayer != null)
{
mPlayer.start();
seekHandler.postDelayed(run, 0000);
// Toast.makeText(ctx, "pause", 2000).show();
selPosition = currentsongindex;
if (adapter != null)
adapter.notifyDataSetChanged();
playpause.setBackgroundResource(R.drawable.play_pause_press);
}
}
}
@Override
public void onDestroy()
{
super.onDestroy();
try
{
seekHandler.removeCallbacks(run);
}
catch (Exception e)
{
}
}
// ===========================================class for getsonglist============================================
class getSongList extends AsyncTask<void, void,="" boolean="">
{
@Override
protected Boolean doInBackground(Void... params)
{
// ArrayList<string> mStringsmyurls = new ArrayList<string>();
String SOAP_ACTIONname = "ns_songlist/get_song_name_list";
String METHOD_NAMEname = "get_song_name_list";
SoapObject result = null;
String NAMESPACE = "ns_songlist";
String URL = "http://exporterp.in/vm/ws_songlist.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAMEname);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTIONname, envelope);
} catch (SocketTimeoutException e) {
return false;
} catch (IOException e) {
return false;
} catch (XmlPullParserException e) {
return false;
}
try {
result = (SoapObject) envelope.getResponse();
if (result != null) {
for (int i = 0; i < result.getPropertyCount(); i++) {
String musicname = ""
+ result.getProperty(i).toString();
if (!sdcard.contains(musicname))
{
MusicData obj = new MusicData();
obj.name = musicname.replace(".mp3", "");
obj.path = "http://exporterp.in/vm/songs/"
+ musicname.replace(".mp3", "") + ".mp3";
obj.isDownload = true;
arrSongList.add(obj);
}
}
return true;
} else
return false;
} catch (SoapFault e) {
return false;
} catch (Exception e) {
return false;
}
}
// @Override
// protected void onProgressUpdate(Void... values) {
// super.onProgressUpdate(values);
// }
}
// ===============================class for show dialogebox======================================================
class load_media_from_url extends AsyncTask<void, void,="" boolean="">
{
ProgressDialog pd = null;
@Override
protected void onPreExecute() {
pd = new ProgressDialog(ctx);
pd.setMessage("Loading...");
pd.setCancelable(false);
pd.show();
}
@Override
protected Boolean doInBackground(Void... params) {
return new getSongList().doInBackground();
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (pd != null && pd.isShowing())
pd.dismiss();
// freeAudioAdapter.addAll(arrList);
// adapter.addAll(arrSongList);
adapter = new CustomAdaptor1();
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
if (!result)
Toast.makeText(ctx, "Error in Downloading File...",Toast.LENGTH_SHORT).show();
// else
// Toast.makeText(ctx, arrSongList + "", 2000).show();
}
}
public void downloadMusic(String mname, int position)
{
if (Utils.isInternetConnected(ctx)) {
new downloadMusicTask(mname, position).execute();
} else {
Toast.makeText(ctx,
"Please Connect to Internet For Load More Music...",
Toast.LENGTH_SHORT).show();
}
}
class downloadMusicTask extends AsyncTask<void, integer,="" boolean=""> {
String musicname = "";
int position = 0;
ProgressDialog mProgressDialog = null;
public downloadMusicTask(String mname, int pos) {
musicname = mname;
position = pos;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog = new ProgressDialog(ctx);
mProgressDialog.setMessage("Downloading Music..");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
}
@Override
protected Boolean doInBackground(Void... params)
{
String uri = musicurl + musicname + ".mp3";
File f = new File(Environment.getExternalStorageDirectory()
.getPath()
+ "/"
+ getResources().getString(R.string.app_download));
if (!f.exists()) {
f.mkdir();
}
f = new File(Environment.getExternalStorageDirectory().getPath()
+ "/" + getResources().getString(R.string.app_download)
+ "/music");
if (!f.exists()) {
f.mkdir();
}
if (folderPath == null || folderPath.equals("")) {
folderPath = Environment.getExternalStorageDirectory()
.getPath()
+ "/"
+ getResources().getString(R.string.app_download);
}
StorePath = folderPath + "/music/" + musicname + ".mp3";
// Toast.makeText(ctx, StorePath+"storepath diaply",7000).show();
try
{
URL url = new URL(uri);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(StorePath);
byte data[] = new byte[1024];
int count;
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress((int) ((total * 100) / lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
}
catch (Exception e)
{
return false;
}
return true;
}
@Override
protected void onProgressUpdate(Integer... values)
{
if (mProgressDialog != null)
mProgressDialog.setProgress(values[0]);
}
@Override
protected void onPostExecute(Boolean result)
{
super.onPostExecute(result);
if (mProgressDialog != null && mProgressDialog.isShowing())
mProgressDialog.dismiss();
if (result)
{
arrSongList.get(position).isDownload = false;
File f=new File(StorePath);
if(f.exists())
{
//f.delete();
MediaScannerConnection.scanFile(ctx, new String[] { f.getAbsolutePath() },new String[] { "audio/*" },null);
}
// arrSongList.clear();
// countaudio() ;
adapter.notifyDataSetChanged();
// countaudio() ;
}
else
{
Toast.makeText(ctx, "File Download Error", Toast.LENGTH_SHORT).show();
}
}
}
// private void getMediaFileName()
// {
// if (folderPath == null || folderPath.equals(""))
// {
// folderPath = Environment.getExternalStorageDirectory().getPath()
// + "/" + getResources().getString(R.string.app_download);
// }
// String StorePath = folderPath + "/music";
// File mfile = new File(StorePath);
//
// arrSongList = new ArrayList<musicdata>();
//
// if (mfile.exists())
// {
// String[] files = mfile.list();
// if (files.length > 0)
// for (String file : files)
// {
// File f = new File(file);
// String musicname = "" + f.getName();
// // arrSongList.add(musicname);
//
// if (!arrSongList.contains(musicname))
// {
// // arrSongList.add(musicname);
// }
// }
// }
// }
}
|
|
|
|
|
And you believe that someone is going to trawl through that unformatted code dump for you? Please edit your post, remove all the code not relevant to the problem, and explain exactly what the problem is.
|
|
|
|
|
Hello to all,
I don't know if this is allowed to post the new jobs in this forum or where to put it, but I am looking for person who is able to make panorama viewer for 4 x 360°images with 6000x3000 px resolution with gyroscope support. Something like in this link: http://www.skorupski-studio.pl/panoramy/test.html .If you are interested in, please contact me at marprochazka@gmail.com for more informations. Thank you.
Best Regards,
Martin
|
|
|
|
|
No it's not allowed, and you have been a CodeProject member long enough to know that. If you want to advertise here then contact the sales department and pay for the service.
|
|
|
|
|
Thank you Richard for advice. I am glad you know what I know.
Martin
|
|
|
|
|
Hi everyone,
I need to capture a video of nearly 30 seconds and upload it to server. Tell me the possible ways to achieve it.
Thank you
|
|
|
|
|
Member 11605078 wrote: Tell me the possible ways to achieve it. It all depends on how you want to achieve it. You will find lots of code samples to help you at http://www.codeproject.com/KB/android/[^].
|
|
|
|
|
I have built a dictionary WEB app using ASP.NET. While building web app, I was using any number of html tags using loops for the meanings of different words. Some words have 20 meanings, some have fewer, some of them have only 1 meaning.
My question is how I can use the same functionality in Android? AFAIK, I use fixed number of textviews in Android which are declared in XML. So what should I use for handling any number of meanings in this case?
Thanks in advance.
|
|
|
|
|
|
I am currently programming in Android websocket without using browser. Few 3rd party Java libraries provides such facility to connect a websocket without using browser.
The websocket server originally programmed as OpenFire plugin. It is exposed to internet via reverse proxy using NGINX server.
I have 2 android phones, one I use a WIFI hotspot and another I use to test the websocket.
The hotspot phone is Android 4.0.4.
The test phone is Android 4.4.4.
The websocket connection if kept idle is closing after 1 minute automatically. But as per the configuration it should only get closed after 3 minutes.
It is properly working if the internet connection is established with the company provided WIFI internet.
|
|
|
|
|
Hello,
I am a beginner in android and I created a project that provides access to a camera with another activity gallery.
I would like to view pictures taken by the camera in the gallery.
here is my code of activity gallery:
public class gallerie extends ActionBarActivity {
Integer[] imageIDs = {
R.drawable.a,
R.drawable.b
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallerie);
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position,long id)
{
Toast.makeText(getBaseContext(), "pic" + (position + 1) + " selected",
Toast.LENGTH_SHORT).show();
ImageView imageView = (ImageView) findViewById(R.id.image1);
imageView.setImageResource(imageIDs[position]);
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context context;
private int itemBackground;
public ImageAdapter(Context c)
{
context = c;
TypedArray a =obtainStyledAttributes(R.styleable.MyGallery);
itemBackground = a.getResourceId(R.styleable.MyGallery_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return imageIDs.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(imageIDs[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(400, 400));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_gallerie, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Code the class that contains the camera:
private GoogleMap mMap;
private LatLng myPosition;
int TAKE_PHOTO_CODE = 0;
public static int count=0;
private void setCamera(Bundle savedInstanceState){
final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/picFolder/";
File newdir = new File(dir);
newdir.mkdirs();
Button capture = (Button) findViewById(R.id.btn_photo);
capture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
count++;
String file = dir + count + ".jpg";
File newfile = new File(file);
try {
newfile.createNewFile();
} catch (IOException e) {
}
Uri outputFileUri = Uri.fromFile(newfile);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
Log.d("CameraDemo", "Pic saved");
}
}
|
|
|
|
|
Ibrahim.elh wrote: I would like to view pictures taken by the camera in the gallery. Have you considered something like:
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(android.provider.MediaStore.Images.Media.CONTENT_TYPE);
startActivityForResult(intent, 1);
or
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I want to see the source code of android registered SIM Tool kit, anyone can share me with
|
|
|
|
|
Member 2458467 wrote: I want to see the source code Then you need to use Google to search for it. This site does not provide code to order.
|
|
|
|
|
Because I find examples open sub menu and main menu of GSM, I used SIM ToolKit, but an error when typing the following:
When i run Start->Programs->Accessories->Communications->HyperTerminal in winxp, I type command:
AT
OK
AT+STGI=0
ERROR
AT+STGR=99
ERROR
AT
OK
I use SIM toolkit but when i type: AT+STSF=1, AT+STGI = 0,... be error, you know why ?
|
|
|
|
|
Dear sir i want to develop Android application about "Search your Doctor ".. to please give some guidline . i m very thankfull to you and your team..
|
|
|
|
|
Member 10840906 wrote: i want to develop Android application... So what is your specific question(s)?
Member 10840906 wrote: about "Search your Doctor ".. What this is is only known to you at this point. Please elaborate.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|