Hi
I choose a number from a list and start the call activity.I want that when call is finish it will back to my list activity.But My current code remains in call log activity when call finishes.
Any help will be great for me.
thanks in advance.
regards
goutom
here is my code..
package police.helpline;
import java.util.ArrayList;
import java.util.List;
import police.login.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class Helpline extends Activity {
private Context context;
private ListView listview;
private List<List_Content> list;
private List_Content listcontent;
private List_ArrayAdapter listarrayadapter;
private PhoneStateListener mListener;
private TelephonyManager mTelMgr;
private Intent callIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.hepline);
Initialization();
SetDataToList();
SetListViewOnClickListener();
}
public void Initialization()
{
context = Helpline.this;
listview = (ListView)findViewById(R.id.list_helpline);
list = new ArrayList<List_Content>();
listcontent = new List_Content("Emergency - ","5556");
list.add(listcontent);
listcontent = new List_Content("Emergency - ","5554");
list.add(listcontent);
listcontent = new List_Content("Operator Service - ","100");
list.add(listcontent);
mListener = new CallEndedListener();
mTelMgr = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
mTelMgr.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE);
}
public void SetDataToList()
{
listarrayadapter = new List_ArrayAdapter(context, R.id.typeandnumber, list);
listview.setAdapter(listarrayadapter);
}
public void SetListViewOnClickListener()
{
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int index,long id) {
callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+list.get(index).number.trim()));
startActivity(callIntent);
}
});
}
public class CallEndedListener extends PhoneStateListener {
boolean called = false;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (called && state == TelephonyManager.CALL_STATE_IDLE) {
called = false;
mTelMgr.listen(this, PhoneStateListener.LISTEN_NONE);
try {
Helpline.this.finish();
Intent t = new Intent(Helpline.this, Helpline.class);
t.setAction(Intent.ACTION_MAIN);
startActivity(t);
} catch (Exception e) {
e.printStackTrace();
}
} else
if (state == TelephonyManager.CALL_STATE_OFFHOOK)
called = true;
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment