繁体   English   中英

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收到adb shell am broadcast -a android.intent.action.BOOT_COMPLETED ,应用程序说:正在运行!

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

我的代码在这里;

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设备具有安全应用程序。 这些应用有时会锁定您的自动启动模式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM