当我试图在电话停止响铃并且它一直强制关闭时开始活动时。
所以这是我的广播接收器
public class Incoming extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
MyPhoneStateListener phoneListener=new MyPhoneStateListener();
TelephonyManager telephony = (TelephonyManager)
arg0.getSystemService(Context.TELEPHONY_SERVICE);
phoneListener.context = arg0;
telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
}
这应该开始活动
public class MyPhoneStateListener extends PhoneStateListener {
int prevstate;
public void onCallStateChanged(int state,String incomingNumber){
if(prevstate==TelephonyManager.CALL_STATE_OFFHOOK && state == TelephonyManager.CALL_STATE_IDLE){
Log.i("PARm","Here the activity should start");
}
else if(prevstate==TelephonyManager.CALL_STATE_RINGING && state == TelephonyManager.CALL_STATE_IDLE){
Log.i("PARM","Here the activity should start");
}
switch(state){
case TelephonyManager.CALL_STATE_IDLE:
Log.d("DECallNoteActivity.get getContext();BUG", "IDLE");
prevstate = state;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d("DEBUG", "OFFHOOK");
prevstate = state;
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.d("DEBUG", "RINGING");
prevstate = state;
break;
}
}
}
如果您能告诉我在这种情况下如何获取上下文以启动 Activity 或如何启动它,我会很高兴。
谢谢你。