Broadcast Receiver Not Working After Device Reboot in Android

前端 未结 7 1696
花落未央
花落未央 2020-11-29 17:12

I have already checked all the related questions and have not found any solution for this problem. So this is an absolutely new problem for me.

What I Have

相关标签:
7条回答
  • 2020-11-29 17:53

    The way IntentFilters work is that each <intent-filter></intent-filter> contains one way of firing up the component. If you have multiple ways of firing it up (like two actions that you want to listen to in one BroadcastReceiver), you'll need an independent <intent-filter></intent-filter> definition for each.

    Hence, you can try changing:

    <receiver android:name=".mics.BootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        </intent-filter>
    </receiver>
    

    to:

    <receiver android:name=".mics.BootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    
        <intent-filter>
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        </intent-filter>
    </receiver>
    

    Read more here: Intents and Intent Filters | Android Developers

    EDIT

    If it still doesn't work, you can try to test if your manifest declaration is done correctly. Try executing the following command in your terminal, keeping the test device connected to the computer:

    adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.app.myapp/.mics.BootReceiver
    

    If this doesn't work, you should recheck the relative package declaration of the receiver in your manifest file.

    EDIT 2

    It may sound weird but try following these steps:

    • Uninstall the app from your phone (ensure it is uninstalled for all users)
    • Reboot your phone
    • Clean the project
    • Build and run the project in your device again
    0 讨论(0)
提交回复
热议问题