android - Android OREO - PHONE_STATE 广播接收器在杀死应用程序后未触发
问题描述
我已经在清单文件中注册了我的接收器,并在我的应用程序处于活动状态时接收触发器。当我杀死我的应用程序时没有收到电话状态请注意 - (OS IS OREO)
显现
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.progdest.prospy">
<uses-permission
android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"
/>
<uses-permission
android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<receiver android:name=".CallReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action
android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<activity
android:name=".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>
</application>
</manifest>
广播类
public class CallReceiver extends BroadcastReceiver {
String CALL_TYPE = "OUTGOING" ;
Boolean TALKING = false;
@Override
public void onReceive(Context context, Intent intent) {
showToast(context,"MAIN");
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)){
showToast(context,"INCOMING" );
// incoming = 1;
}
else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDLE)){
showToast(context,"CALL ENDED" );
}
else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
showToast(context,"CALL ACTIVE");
}
}
public void showToast(Context cntxt,String msg){
Toast.makeText(cntxt,msg,Toast.LENGTH_SHORT).show();
}
}
我已经在清单文件中注册了我的接收器,并在我的应用程序处于活动状态时接收触发器。当我杀死我的应用程序时没有收到电话状态请注意 - (OS IS OREO)
解决方案
推荐阅读
- c - ZeroMQ Radio/Dish 不接收消息
- c++ - 进一步传递可变参数
- matlab - 有没有办法在 MATLAB 中输出 ode 求解器的中间计算?
- javascript - 如何将 Zip 文件从 s3 存储桶下载到 node.js lambda 函数中的本地目录
- jenkins - 同一个 repo 和同一个分支中的多个 Jenkins 文件用于不同的目的
- html - 从输入字段获取原始文本而不是日期对象
- ssis - 即使使用错误的 Kingswaysoft 连接参数,SSIS 部署的项目也能成功验证
- r - 根据 R 中的条件计算日期之间的平均差
- react-native-flatlist - React Native Draggable Flatlist 仅适用于 ScrollView 但错误?
- java - 如何在消费者 Java 8 中抛出异常