0

My implementation of BootBroadcastReceiver

Permission taken in manifest :<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Intent filter in manifest for BootBroadcastReceiver :

<receiver android:name=".receivers.BootBroadcastReceiver" android:enabled="true" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE"/>
            </intent-filter>
        </receiver>

The additional actions are result of some threads read online.

Below is implementation class :

public class BootBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Application boot event");
        Toast.makeText(context, "Boot completed", Toast.LENGTH_SHORT).show();
    }
}

But somehow on reboot or power on I am not able to get this boot complete I added the toast also. No toast shown.

Also some people suggested make application install on internal memory only because the boot complete broadcast is not delivered to apps on external storage. By setting flag in manifest android:installLocation="internalOnly" I also did this but not worked for me. What might be wrong ?

Devices used for testing :

Moto E3 power (Android 6.0 ), Lenovo A6020a40 ( Android 5.1.1)
Prashant
  • 4,474
  • 8
  • 34
  • 82
  • 1
    Heve you added `` to your AndroidManifest.xml? – Mateus Gondim Jun 09 '17 at 13:02
  • Which kind of android do you use? Depending on some custom roms, there are more intent actions, that you may have to take into account. i.e. htc fast boot com.htc.intent.action.QUICKBOOT_POWERON – JacksOnF1re Jun 09 '17 at 13:17
  • @JacksOnF1re please have look at the updated question – Prashant Jun 09 '17 at 13:21
  • just checking, has the app been launched by you at least once before the reboot? That's required in order to receive the broadcast. – Mateus Gondim Jun 09 '17 at 13:51
  • @MateusGondim Yes launched by me, I know what your saying as per android documentation only applications which are launched once by user will get these boot broadcasts by system. – Prashant Jun 09 '17 at 15:03
  • Where is the `` element in the manifest? It needs to be between the `` tags, but not inside anything else, like ``. Are you sure the `name` attribute is pointing to the right place? That is, `BootBroadcastReceiver` is in the `receivers/` folder? Do those devices have any additional settings or app management mechanisms that restrict apps from starting at boot, or running in the background? Have you tested on an emulator? – Mike M. Jun 10 '17 at 01:10
  • @MikeM. element is in between but surely out side & also name points to the required class if I press Ctrl+Click opens the receiver class in Editor, not sure about mobile specific settings as no special settings seen in app settings or permission settings – Prashant Jun 12 '17 at 06:15
  • Where is the `` element? It goes _outside_ of the `` tags. (Guess I forgot to ask that last time.) Also, have you gotten this to work at all? That is, are you saying that it's just those devices where this isn't working? Or it's never worked? – Mike M. Jun 12 '17 at 06:21
  • @MikeM. Its inside ..., but before & outside ..., I think I am missing minor thing here but can't find what it is – Prashant Jun 12 '17 at 06:28
  • Well, if everything you've posted and commented is in order, that's all you need on a standard system. I'd suggest you test on an emulator, to determine if it is your devices' setups that could be the cause. I know some Lenovos have additional security management available through a custom app, named something like Security HD. Dunno about Motorola. I would also mention that your app might not get the boot broadcast for some time after the device boots, so if you're looking for it to popup right away, you might be missing it. Maybe use something more noticeable, like a `Notification`. – Mike M. Jun 12 '17 at 06:46
  • @MikeM. thanks for your time, BTW Moto and lenovo are now single company, I will test this on emulator & then let you know the results. – Prashant Jun 12 '17 at 07:23

0 Answers0