Android 6.0 Broadcast Receiver don't receive BOOT_COMPLETE

ぐ巨炮叔叔 提交于 2019-12-11 05:14:45

问题


My receiver is not working with Android 6.0 Marshmallow.

I am sending a broadcast through adb shell, see below:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED received if application was open, App say:Working!

But if the application was not open, it has not been returning anything.

My code is here;

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();
    }
}

Edit: I have very interesting info, My code is working on samsung (Android 6.0) devices. But my (Android 6.0) devices not responding me


回答1:


change this

<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>

to this

<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>

hope it helps




回答2:


I fixed, some new android devices have security application by default. some times these apps lock your auto-start mode.



来源:https://stackoverflow.com/questions/41758668/android-6-0-broadcast-receiver-dont-receive-boot-complete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!