我在手机状态监听器中遇到问题。我想从activity
事件中调用一个onCallStateChanged
。当我收到来电时,我想拨打一个activity
并处理当前电话号码的交易(我目前通过来电获得)。
但我无法使用以下代码进入ShowPhoneStateDialogActivity
活动。请纠正我的错误。提前致谢。
我的代码是,
case TelephonyManager.CALL_STATE_RINGING:
Log.d("PHONE:", "RINGING");
Log.w("Call STATE:", "RINGING");
if (!sess.getCallActive()) {
sess.setCallActive(true);
sess.setActiveMobileNo(incomingCallNumber);
this.endActivecall();
Intent intent = new Intent(context,ShowPhoneStateDialogActivity.class).setAction("incomingNumber");
intent.putExtra("Phoneno", incomingCallNumber);
Log.i("CURRENT ACTIVITY",this.getClass().getSimpleName());
Log.i("CURRENT CONTEXT","Context:"+context);
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(intent);
break;
} else {
this.endActivecall();
}
break;
endActivecall
函数是,
public void endActivecall() {
TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
// telephonyService.silenceRinger();
telephonyService.endCall();
Log.i("CALL STATE ACTION:", "Call end");
Log.i("ACTIVE_MOBILENO:", sess.getActiveMobileNo());
} catch (Exception e) {
e.printStackTrace();
}
答案 0 :(得分:2)
而不是代码context.startService(intent)
,请尝试调用context.startActivity(intent)
。