1

I created a boot receiver class:

public class BootReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
         Log.d("Boot receiver","Working")
    }
}

My manifest file:

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

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

I used the adb command - am broadcast -a android.intent.action.BOOT_COMPLETED

Still i cant be sure whether it is working.How can i test it?

Daniel Sagayaraj
  • 177
  • 2
  • 20

2 Answers2

1

I think you have missed the @Override for on receive.

@Override
public void onReceive(Context context, Intent intent) {
 Log.d("Boot receiver","Working")
}

in my manifest i have;

 <receiver
    android:name=".BootUpReceiver"
    android:enabled="true"
    android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
     <intent-filter>
       <action android:name="android.intent.action.BOOT_COMPLETED" />    
       <category android:name="android.intent.category.DEFAULT" />
     </intent-filter>
 </receiver>

and;

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

in BootUpReceiver.java i have;

public class BootUpReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {

        Intent i = new Intent(context, Main.class);  
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);  
    }    
}

You should just be able to see your Log in the logcat, try using System.out.println("BOOT RECEIVED"); instead of Log

matty357
  • 637
  • 4
  • 16
0

Keep in mind that packages have different states (Major changes came from Android 3.1).
If the user is not opening the app by himself (at least once) than your package will not receive this intent.

Otherwise it will be really easy to run some malicious code without user interaction.

As you can imagine for security reasons. There you can find more information: Trying to start a service on boot on Android

Unless you will place your APK in /system/apps folder and will sign it with system certificate.

P.S.: There is some flag that you can pass with the intent, might be interesting for you FLAG_INCLUDE_STOPPED_PACKAGES

Community
  • 1
  • 1
EvZ
  • 11,889
  • 4
  • 38
  • 76
  • I use the receiver to start the app when the device starts, so the app is never running in my situation, and it always starts on boot up – matty357 Apr 15 '15 at 12:49
  • I fully understand and agree with the security risks. But I don't understand why my receiver works and starts the app with no extra intent flags. Maybe my HTC m7 allows you to do this? – matty357 Apr 15 '15 at 13:10