BOOT_COMPLETED sporadically not sent on bootup - android

I am using BOOT_COMPLETED Intent to start a service of mine.
However, like 1 time in 5, the BOOT_COMPLETED intent is not sent, thus my service fails to start. I have tried using WakefulBroadcastReceiver and other things but I can't understand why it sometimes isn't sent. I mean the device is working, you can connect to it via adb and so on, it's just that BOOT_COMPLETED is not sent. Does anyone have an idea about what is going on?
I am on Android 4.4.4 Kitkat. I am aware of the stopped-state issue, however I have used Xposed to disable that and it still doesn't work so it ought to be something else.

Maybe Manifest added:
<receiver android:name=".services.ShutdownReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
In created class :
public class ShutdownReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, GPSService.class);
context.startService(i);
}
}

Related

How to determine Device startup event in android

I want to mantain a log in my android application , log will contain the Device Started (Bootup) and Device Stop Times. Any Idea how to do this ?
I have to start my application on Bootup , But how to determine that application is started on Bootup ?
I have searched but could not find a better solution.
Use BroadCastReceiver to receive BOOT_COMPLETED broadcast. This broadcast is thrown in device startup
The receiver will be like
<receiver
android:name="ReceiverName"
android:enabled="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
You will need to use the following persmission
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
now in code write a BroadCastReceiver class like
public class ReceiverName extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// do startup tasks or start your luncher activity
}
}
You can use BroadcastReceiver component for this purpose. Using this you can detect various events of your device like booting.
To Detect Booting process you need to give permission in AndroidManifest.xml as below,
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
Then you need to create a BrodacastReceiver which will handle this,
In the onReceive() method the corresponding BroadcastReceiver would then start the event,
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent service = new Intent(context, WordService.class);
context.startService(service);
}
}

How to start an application directly (without asking) at startup on Android 4.0

I want to start my application at startup in Android 4.0. To do that, I wrote some codes and these are completely the same with the #Ahmad's codes (in the answer). However, although I select my application as always, when tablet opens, it asks 'What do you prefer?' (Android's default launcher or my application). I don't want it to ask that question and it must start my application automatically.
Use the BOOT_COMPLETED Intent.
Broadcast Action: This is broadcast once, after the system has
finished booting. It can be used to perform application-specific
initialization, such as installing alarms. You must hold the
RECEIVE_BOOT_COMPLETED permission in order to receive this broadcast.
In your Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Set up a Broadcastreceiver:
<receiver android:name="com.example.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
This is how your BroadcastReceiver could look like:
public class MyBroadcastreceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, MyActivity.class);
startActivity(i);
}
}

How to start the application after boot complete in android version 3.1 and above?

I got to know boot complete intent is not supported by android version 3.1 and above from here. But in my application. I want to start services automatically in my application after device is rebooted. I do not want user to start my application manually. How can I do it ? Thanks for help in advance.
What makes you think the ACTION_BOOT_COMPLETED broadcast is no longer sent? I make frequent use of it, and so do others. Just be sure you have RECEIVE_BOOT_COMPLETED permission in your manifest.
try the following steps to start the application after boot:
create a class which extends BroadcastReceiver:
public class AutostartService extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
System.out.println("in broad....");
if ((intent.getAction() != null) && (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")))
{
System.out.println("in broadcast receiver.....");
Intent i = new Intent(context, Splash.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
and also add this in android manifest file:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".AutostartService" android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Well this is pretty old now and probably most people learned it but still might be useful.
From 3.1+ and on, in order to receive the BOOT_COMPLETED, your app must be started at least once by the user.
NOTE: This rule doesn't apply to /system apps

How to start an Application at boot up in Android?

I am trying to make an App in Titanium which launches on Startup i.e. as the mobile device startsup. I have seen code written at several places which states to do entry into the andsoid manifest file and some code like
#Override
public void onReceive(Context context, Intent intent) {
Intent myIntent = new Intent(context, YourActivity.class);
context.startActivity(myIntent);
}
But i am not able to figure out that where to put this code. In which file ?? and where ?
This 2 answers will do what you need:
Start BroadcastReceiver after some system broadcast:
https://stackoverflow.com/a/7877466/988434
Start BroadcastReceiver on boot:
https://stackoverflow.com/a/8544151/988434
in you BroadcastReceiver you'll implement just call whatever Service/Activty you need.
There an example for that in the question for the 2 answers above.
Tell me if you have any problems unanswered after reading those =].
You have to listen to the BOOT_COMPLETED intent filter. The piece of code you just quoted is from a BroadcastReceiver which will be firing up when the device will boot.
This class has to extend from BroadcastReceiver:
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
...
}
}
Then, you have to register that receiver in your manifest file by doing the following:
<receiver
android:enabled="true"
android:name="your_package.BootReceiverClassName"
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>
Also you need the following permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
By the way you have to make sure that the app is not installed on the SD Card otherwise it won't work (but there are possible workarounds).

Start Alarm on Android without having the application running

My idea is to set an alarm for a specific date in my application, but I want to be able to have the alarm ringing at the set date, even if my application isn't running at all.
How can I achieve this?
Thanks in advance!
I'd start a service when the device is booted - that service should take care about the alarming when the time has come.
To make your service be started at boot time you need the following things in your AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
in the <manifest> tag
<receiver android:name="com.yourpackage.AlarmingBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
in your <application> tag
Additionally you need your AlarmingBroadcastReceiver, should look something like that to start the service:
public class AlarmingBroadcastreceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Intent startServiceIntent = new Intent(context, AlarmingService.class);
context.startService(startServiceIntent);
}
}
whereas AlarmingService.class is the class name of your service that finally takes care about the alarming stuff
You will need to create a onBoot BroadCast Receiver so when the device is started your application will get control to set up alarms.

Categories

Resources