首页 > 解决方案 > 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)

标签: androidbroadcastreceiverandroid-8.0-oreo

解决方案


推荐阅读