检测拨出电话

时间:2018-06-15 07:10:47

标签: android broadcastreceiver

我的android应用程序需要在连接之前检测所有传出呼叫“NEW_OUTGOING_CALL”,但是当应用程序关闭时,我的“BroadcastReceiver”不会检测传出呼叫。也许有人知道如何解决它?也许我需要“服务”或者还有其他方式?

AndroidManigest.html

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.WRITE_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
 ...

        <receiver android:name=".OutgoingCallReceiver" >
            <intent-filter android:priority="999">
                <action android:name="android.intent.action.NEW_OUTGOING_CALL"
                    />
            </intent-filter>
        </receiver>

OutgoingCallReceiver.java

public class OutgoingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Log.v(Constants.TAG, "ONRECEIVE");

    //when app is closed (after OnDestroy()) this code is no longer called
    //But when app is onPause(), this code is called
}
}

0 个答案:

没有答案