Android 6.0 广播接收器不接收 BOOT_COMPLETE

Android 6.0 Broadcast Receiver don't receive BOOT_COMPLETE

我的接收器无法使用 Android 6.0 Marshmallow

我正在通过 adb shell 发送广播,见下文:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED 收到 如果应用程序已打开,App say:Working!

但如果应用程序未打开,则不会返回任何内容。

我的代码在这里;

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.berate.rebootreceiverfromb3r0">
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" android:protectionLevel="signature|development"></uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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


        </activity>

        <receiver android:name="com.example.berate.rebootreceiverfromb3r0.Yakala_Receiver">
                <intent-filter>
                    <category android:name="android.intent.category.DEFAULT"></category>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                </intent-filter>
            </receiver>
    </application>

</manifest>

Receiver.Java;

public class Yakala_Receiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context,"i got it ",Toast.LENGTH_SHORT).show();
    }
}

编辑:我有非常有趣的信息,我的代码在三星 (Android 6.0) 设备上运行。但是我的 (Android 6.0) 设备没有响应我

改变这个

<receiver android:name="com.example.berate.rebootreceiverfromb3r0.Yakala_Receiver">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT"></category>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>

到这个

<receiver android:name="com.example.berate.rebootreceiverfromb3r0.Yakala_Receiver"  android:enabled="true" android:exported="true">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT"></category>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>

希望对您有所帮助

我已修复,一些新 android 设备默认具有安全应用程序。有时这些应用程序会锁定您的 auto-start 模式。