4

I need my app to be started automatically once after the phone reboot and Power-on.

I used the code provided at AutoStart an Application at boot up and now my android app starts automatically after the phone reboot (restart).

Now, consider that instead of doing a phone reboot, I have used Phone power off (Shut phone down) option. After the phone power on, my app is not started automatically as expected. Can you please explain what I have missed.

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

<receiver android:enabled="true" android:name=".BootUpReceiver" 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>



public class BootUpReceiver extends BroadcastReceiver
{
    private static SharedPreferences aSharedSettings;

    @Override
    public void onReceive(Context context, Intent intent) 
    {
        aSharedSettings = context.getSharedPreferences("MYPreferences", Context.MODE_PRIVATE);
        boolean isUserLoggedIn = aSharedSettings.getBoolean(kEY.AUTHENTICATED, false); 
        if(isUserLoggedIn) 
        {
Intent aServiceIntent = new Intent(context, HomeView.class);
                aServiceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(aServiceIntent); 
}

    }
}

Thank You.

onkar
  • 4,427
  • 10
  • 52
  • 89

5 Answers5

3

Does it work as intended if you launch the application manually at least once before rebooting the phone, and not 'Force-close' it?

Have a look at:

Android : android.intent.action.BOOT_COMPLETED on ICS and Gingerbread

Boot Completed Regression Confirmed

Community
  • 1
  • 1
etienne
  • 3,146
  • 1
  • 24
  • 45
2

There are a few things you can try.

Firstly check that your app installLocation in the AndroidManifest.xml is set to android:installLocation="internalOnly" this makes sure that the app is on the local storage. Apps installed to the sdcard will not receive the BOOT_COMPLETE intent.

Also I would remove <category android:name="android.intent.category.DEFAULT" /> it is not necessary.

And the last thing you can try is using a full package name:

    <receiver android:enabled="true" 
              android:name="com.myapp.receivers.BootUpReceiver" 
              android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
Chris.Jenkins
  • 13,051
  • 4
  • 60
  • 61
  • Hi, thanks for the response. I made all the 3 changes. But its not working. I am using HTC one V. For me, in HTC ONE V, my android app starts automatically after the phone reboot (restart). However, when I use "Phone power off (Shut phone down)", this BroadcastReceiver is not called, and the restarting is not working. So I feel, there is no problem with BroadcastReceiver.. I checked this with the other android models and found that the auto-restart works properly in 'Phone power off'. Only problem in HTC one V. Any suggestions please.. –  Dec 20 '12 at 16:16
  • So put simply it works when rebooting but not when you come from "Powered Off">? – Chris.Jenkins Dec 20 '12 at 17:05
  • Yes Chris.. it works when rebooting but not when come from "Powered Off". –  Dec 20 '12 at 21:50
  • I can only see that as a device bug, there is no 'special' way to designate if you are coming from reboot/boot in the manifest. :/ – Chris.Jenkins Dec 20 '12 at 21:57
2

Try to add

<category android:name="android.intent.category.LAUNCHER" />

instead of

<category android:name="android.intent.category.DEFAULT" />. 

And also check the value of isUserLoggedIn.

kumar
  • 691
  • 1
  • 7
  • 16
  • Thanks Kumar. Tried this. But its still not working in Phone power off (Shut phone down) in HTC one V. However, in other model phones its working. Suggestions please.. –  Dec 20 '12 at 16:18
1

Are you using a HTC device? If so, you may have a feature enabled called "Fast-Boot"

See this link for details.

Detect if HTC "Fast boot" is enabled

Community
  • 1
  • 1
Kuffs
  • 35,581
  • 10
  • 79
  • 92
  • Hi, thanks for the fast response. Yes I am using HTC one V. For me, in HTC ONE V, my android app starts automatically after the phone reboot (restart). However, when I use "Phone power off (Shut phone down)", this BroadcastReceiver is not called, and the restarting is not working. I checked this with the other android models (samsung and sony) and found that the auto-restart works properly in 'Phone power off'. Only problem in HTC one V. I tried ACTION_SCREEN_ON and ACTION_USER_PRESENT, but its not working. Help please.. –  Dec 20 '12 at 16:13
1

the name of the Activity from where you are starting your application, Add this line in your tag.....And let me know it worked or not

  <category android:name="android.intent.category.HomeView" />
Sam-In-TechValens
  • 2,501
  • 4
  • 34
  • 67
  • Thanks for the response samintechvalens.. I tried this, however, still its not working. –  Dec 20 '12 at 16:18