1

I have developed application to start app on boot, but it is working on rooted devices only some of code as below.

permission and receiver in AndroidManifest.xml file is given below.

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

<receiver android:enabled="true" android:name="in.com.appname.StartAppAtBootReceiver"
        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>

below are the class to receive on boot.

public class StartAppAtBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent myIntent = new Intent(context, MainActivity.class);
        myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(myIntent);
    }
}

my question is that this code will work with non rooted devices?
if yes then what is missing because same app is working with rooted devices.

Satyendra
  • 11
  • 1
  • On the un-rooted devices, is your app installed on the SD card ? If so have a look at this link http://stackoverflow.com/questions/19206725/why-receive-boot-completed-doesnt-work-on-my-device – Code_Yoga Oct 09 '15 at 09:08

2 Answers2

0

This must work without root. Else try to use a simple tutorial like: Android AutoStart App after boot

Differences:

  • Check which action occurs.
  • Use startService instead of startActivity

Another tip: Set permissions in top of manifest, and receiver in application-part.

Geert Berkers
  • 653
  • 7
  • 19
  • manifest file is ok as you suggested. I have used startActivity because MainActivity class extends Activity. – Satyendra Oct 09 '15 at 09:17
  • What if you add a service which creates and starts the activity? So use AutoStartUp.java from example, and create and start the activity. – Geert Berkers Oct 09 '15 at 09:32
0

This should work without root.

There are a couple of things to notice:

  1. app must be started at least once before it can receive BOOT_COMPLETED
  2. if app is force closed, it will lose it ability to receive BOOT_COMPLETED until next launch.

Also, permission should be at the root of manifest and not inside application:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.x.y" >
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application
        android:allowBackup="true"
.
.
.

make sure you are not running in above situations.

Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78