BOOT_COMPLETED not received

Do all devices send BOOT_COMPLETED? I want to run Activity on Boot Completed.

I put the following in the manifest:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <receiver android:name=".BootFinished"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> 

Created the following class (receiver):

 import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.widget.Toast; public class BootFinished extends BroadcastReceiver { @Override public void onReceive(Context mContext, Intent intent) { if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { //do something like start an activity or service } try { PackageManager pm = mContext.getPackageManager(); Intent launch = pm.getLaunchIntentForPackage("com.example.afterboot"); mContext.startActivity(launch); } catch (Exception e) { Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT); } } } 

Am I missing something? Thanks!

+2
source share
3 answers
  • Add the full path and, secondly, add permission to your receiver.

      <receiver android:name="com.example.BootFinished" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> 
+5
source

As a starting point, try putting the full path of your receiver in the manifest.

0
source

Possible reasons why broadcast events of the receiver may occur:

  • The receiver is not declared in AndroidManifest.xml Declare the receiver in the manifest file:

  • The recipient in the xml manifest is spelled incorrectly. The Android system is case sensitive. So check your spelling and path in AndroidMainfest.xml

  • AVD works for a long time Reset your avd / device

4. Also, if your application is moved to sdcard.Say, you are registered for android.intent.action.BOOT_COMPLETED, the download event is triggered even before the media scanner scans the SD card.

and all devices that run the android send BOOT_COMPLETE: P Try again and try :) all the best :)

0
source

All Articles