1

I would like to build a boot receiver. Manifest.XML

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

And this is my Receiver Class:

public class BootReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Log.e("-->", "BOOT COMPLETED");
        }
}

If i restart my device i get the message (on my device):

the app xxx was closed

AnjumSKhan
  • 9,647
  • 1
  • 26
  • 38
Trombone0904
  • 4,132
  • 8
  • 51
  • 104

1 Answers1

0

Try to change this in your .manifest

 <receiver android:name=".BootReceiver"
   android:enabled="true"
   android:exported="false"
   android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
 </receiver>

Also Try this out in your Reciever

public class BootReceiver extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
        Toast.makeText(context, "Receiver Called", Toast.LENGTH_LONG).show();
    }
}

Also Add android:persistent="true" in to your manifest tag

Kishan Soni
  • 816
  • 1
  • 6
  • 19