我有一个使用OutgoingCallReceiver类检测去电的应用程序。大部分电话都可以使用。

但是在某些电话上,事件不会到达OutgoingCallReceiver类的功能onReceive()。因此我的应用无法检测到去电。我必须重置为出厂配置才能正常工作。

这是我的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.*******.android.********"
    android:installLocation="preferExternal"
    android:versionCode="28"
    android:versionName="4.2" >

    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_LOGS" />
    <uses-permission android:name="android.permission.WRITE_LOGS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="21"/>
    <uses-feature
        android:name="android.hardware.telephony"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.wifi"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.microphone"
        android:required="true" />
    <uses-feature android:name="android.hardware.camera" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".********"
            android:screenOrientation="portrait" >
            <intent-filter android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.********.android.********.********"
            android:excludeFromRecents="true"
            android:launchMode="singleTop"
            android:screenOrientation="portrait" > <!-- android:theme="@android:style/Theme.Dialog"> -->

            <intent-filter>
                <action android:name="android.intent.action.SEND" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name=".********"
            android:excludeFromRecents="true"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

        <activity
            android:name=".********"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:excludeFromRecents="true"
            android:launchMode="singleTop"
            android:taskAffinity=""
            android:theme="@style/AcceptCallInvisible" >
        </activity>

        <activity
            android:name=".********"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

        <activity
            android:name=".********"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

        <activity
            android:name=".********"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

        <activity
            android:name=".********"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

        <activity
            android:name=".********"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>

        <activity
            android:name=".********"
            android:windowSoftInputMode="adjustResize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.SENDTO" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="sms" />
                <data android:scheme="smsto" />
            </intent-filter>
        </activity>

        <activity
            android:name="com.********.********.********.********.********"
            android:launchMode="singleTask"
            android:screenOrientation="portrait" > <!-- android:launchMode="singleTop" -->
            <intent-filter>
                <action android:name="android.intent.action.CALL" />
                <category android:name="android.intent.category.SAMPLE_CODE" />
            </intent-filter>
        </activity>


        <service android:name=".********" />


        <receiver android:name=".OutgoingCallReceiver" android:exported="true" android:enabled="true">
             <intent-filter android:priority="0" >
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
                 <meta-data />
            </intent-filter>
        </receiver>
        <receiver android:name=".SmsReceiver" >
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
        <receiver
            android:name=".PhoneStateReceiver"
            android:exported="true" android:enabled="true">
             <intent-filter android:priority="0">
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>

    </application>
</manifest>

最佳答案

可能还有其他应用程序正在使用此事件。请尝试将接收器的概率设置为最大整数值。

 <receiver android:name=".OutgoingCallReceiver" android:exported="true" android:enabled="true">
             <intent-filter android:priority="100000" >
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
                 <meta-data />
            </intent-filter>
        </receiver>


有关正确实现它的更多信息,请参考http://android-developers.blogspot.com/2013/05/handling-phone-call-requests-right-way.html

您也可以尝试更改清单条目。在某些OEM上,它可能会提供解析错误。

像这样:

<uses-permission />
...
<receiver>
    <intent-filter> . . . </intent-filter>
    <meta-data />
</receiver>

07-27 15:37