我的应用为NEW_OUTGOING_CALL意图注册了BroadcastReceiver。每次用户拨打电话时,应用都会采取措施(例如记录呼叫)。这曾经在旧版Android中运行良好。从Android 8开始,BroadcastReceiver仅在应用程序启动后的几个小时内捕获此意图。它也没有捕获重启的意图。需要帮助了解更改内容以及如何解决此问题。
Manfest:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.example.OutgoingCallInterceptor"> // 5
<intent-filter android:priority="1">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
代码:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class OutgoingCallInterceptor extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Do something here
}
}
}