一旦拨出电话结束,我试图回到我的活动。我发现了类似的问题并尝试实现代码,但问题是oncallstatechange()方法,状态始终为0,因此一旦调用因为代码是直接进入if循环,条件是状态空闲并回到我的应用程序,因为问题已经解决,我正在进入我的活动,但是电话会立即被绞死.kindly help.thanks提前。
//inside on create...
callListener = new EndCallListener();
mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
//calling on item click
public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3)
{
// TODO Auto-generated method stub
LinearLayout ll = (LinearLayout) ((LinearLayout) v).getChildAt(0);
LinearLayout lc = (LinearLayout) ll.getChildAt(0);
TextView tv = (TextView) lc.getChildAt(3);
String st = tv.getText().toString();//contains phone number
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
Intent i=new Intent(android.content.Intent.ACTION_CALL,Uri.parse("tel:"+st));
startActivity(i);
//finish();
}// onitemclick
//这是我调用我的活动的地方..
class EndCallListener extends PhoneStateListener {
@Override
state-->0 public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
if(TelephonyManager.CALL_STATE_RINGING == state) {
}
if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
//wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.
}
if(TelephonyManager.CALL_STATE_IDLE == state) {
//when this state occurs, and your flag is set, restart your app
startActivity(new Intent(recentcalling.this,recentcalling.class));
}
}
}