2

Does every device send the BOOT_COMPLETED? I want to start an 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!

Robert Estivill
12.6k10 gold badges47 silver badges71 bronze badges
asked Apr 9, 2012 at 22:28
1

3 Answers 3

5
  1. Add full path and secondly add permission in 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>
    
answered Apr 9, 2012 at 22:49
Sign up to request clarification or add additional context in comments.

Comments

1

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

answered Apr 9, 2012 at 22:41

Comments

0

The possible reasons why broadcast reciever events could fail:

  1. Receiver not declared in AndroidManifest.xml Declare the receiver in the Manifest-file:

  2. Receiver in the Manifest xml is misspelled Android-System is case sensitive. So check your spelling and path is correct in the AndroidMainfest.xml

  3. AVD running for a long time Reset your avd/device

4.Also if your app is in moved to sdcard.Say you have registered for android.intent.action.BOOT_COMPLETED,the boot event is triggered even before the mediascanner scans the sdcard.

and all the devices which run android sends BOOT_COMPLETE :P Check again and try :) all the best :)

answered Jan 25, 2013 at 11:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.