I am making a system app. In that I have a requirement is to run a service after boot load WITHOUT A SINGLE TIME LUNCHING THE APP. this question is bit similar to this System App auto starting But it does not have any appropriate solution. Also read that BOOT_COMPLETE_RECEIVER works only when app launched at once.
-
1this may help you http://stackoverflow.com/questions/5051687/broadcastreceiver-not-receiving-boot-completed – H Raval Oct 20 '16 at 08:59
-
yeah, I read about somewhere that some suppliers only allow apps to start automatic if it started once by the user. On which device have you tried? I know for example on some Huawei ones, that you have to enable AutoRun in the device settings, otherwise broadcasts will never work. And you can´t do it programmatically, you have to instruct the user.... – Opiatefuchs Oct 20 '16 at 09:00
-
take a look at this [answer](http://stackoverflow.com/a/6392009/6503228) – devgun Oct 20 '16 at 09:01
-
@kcg Ya you are right. But if it is a system app does same rules applied to it. means its receiver started working only when user open app at least once or their is some way to achieve it . – Vindhya Pratap Singh Oct 20 '16 at 09:10
-
From Android 3.1, BroadcastReceiver will not work until the user has manually launched an activity, This is for provide security . once the user runs the app for the first time then your BroadcastReceiver will run always except it does not Force Stop it. Once activity launch at first time your broadcast receiver will run even after reboot your deice. – devgun Oct 20 '16 at 09:14
3 Answers
Use Broadcast Receiver for getting action after that start service from that broad cast receiver and use START_STICKY service so that if it is killed because of some priority than it's recreate and if you want to continuously run this service in background than WAKE_Lock that service and using Alarm Manager check it is runnig or not.

- 1,101
- 11
- 29
-
This will only works if you have opened app at least once. I want to receive boot complete receiver works even user not opened app single time after installing it. – Vindhya Pratap Singh Oct 20 '16 at 09:09
-
Any instance of broadcast receiver and service is not create without open app once. – MIkka Marmik Oct 20 '16 at 09:14
Set this in manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name="AutoStart"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
AutoStart class
public class AutoStart extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
// Start your service here..
}
}
}

- 2,757
- 1
- 22
- 30
-
This will only works if you have opened app at least once. I want to receive boot complete receiver works even user not opened app single time after installing it. – Vindhya Pratap Singh Oct 20 '16 at 09:09
-
@VindhyaPratapSingh check this [blog](https://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html). – Akash Patel Oct 20 '16 at 09:24
Thanks all for your effort, I finally got answer. Solution: As I stated my app is system app, System work even they not opened at once. Because they are not in stopped state i.e enforce after android 3.1.
Secondly If a user app wants this then Its manifest don't have any "android.intent.category.LAUNCHER" category in activity.
Also by adb you can enable your app by using this command adb shell am broadcast -a com.example.demo.action.LAUNCH --include-stopped-packages (This is not tested)
Some good link to this: http://droidyue.com/blog/2014/01/04/package-stop-state-since-android-3-dot-1/ Static BroadcastReceiver not Working after Installation from ADB

- 1
- 1

- 556
- 5
- 20