0

I'd like the system to trigger my pendingIntent when the phone is off hook on Android devices, is this possible ? I would use the pendingIntent with an IntentService to do some work off the main thread. This would be a battery saver for the end user.

Its very similar to how you can pass a pendingIntent to the AlarmManager, I'd like to pass one to the system and let it trigger when it encounters an incoming call.

4

1 回答 1

1

不,但是您可以使用电话管理器,只需创建一个监听 PhoneStateListener 的类

telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);


@Override
public void onCallStateChanged(int state, String incomingNumber) {
    uiReference.defaultRecipient = incomingNumber;
    if (TelephonyManager.CALL_STATE_RINGING == state) {
    } else if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
    } else if (TelephonyManager.CALL_STATE_IDLE == state) {
    }
}

显现:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
于 2013-07-05T22:44:22.023 回答