Android OREO-杀死应用程序后未触发PHONE_STATE广播接收器

时间:2018-11-26 07:51:40

标签: android broadcastreceiver android-8.0-oreo

我已将接收器注册到清单文件中,并且在我的应用程序处于活动状态时接收触发器。我杀死我的应用程序时未收到手机状态 请注意-(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)

0 个答案:

没有答案