1

我在电话状态监听器中遇到问题。我想activityonCallStateChanged事件中调用一个。当我接到来电时,我想拨打一个电话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();
        }
4

1 回答 1

2

而不是 code context.startService(intent),而是尝试调用context.startActivity(intent)

于 2013-02-25T10:49:08.937 回答