一旦拨出电话结束,我正试图回到我的活动。我发现了类似的问题并尝试实现代码,但问题是 oncallstatechange() 方法,状态一直为 0,因此一旦调用它正在断开连接,因为代码直接进入条件为状态空闲的 if 循环并返回到我的应用程序。虽然问题已解决,但我正在恢复我的活动,但通话立即挂断。请帮助。提前致谢。
//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));
}
}
}