Is android.permission.RECEIVE_BOOT_COMPLETED not required? - android

Does anyone know why my application still receives the ACTION_BOOT_COMPLETED broadcast even when my app doesn't have the permission android.permission.RECEIVE_BOOT_COMPLETED in the manifest file? I thought it was required but a few tutorials I used also didn't have it. A few did. I use my phone running CyanogenMod for testing but I doubt that matters. LogCat shows my "Notified of boot" log upon each boot. See below for code used.
AndroidManifest.xml
<receiver android:name="AlarmReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
AlarmReceiver class
public class AlarmReceiver extends BroadcastReceiver {
private static final String TAG = "MyProgram";
#Override
public void onReceive(Context context, Intent intent) {
try {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Log.d(TAG, "Notified of boot");
}
Intent newIntent = new Intent(context, MyService.class);
context.startService(newIntent);
} catch (Exception e) {
Log.d(TAG, "An alarm was received but there was an error");
e.printStackTrace();
}
}
}
I revisited this on the emulator and successfully reproduced the "problem" on Android 2.1, 2.2 and 2.3. I get an ANR (as expected) since the emulator doesn't have the database my app queries. When I remove all declared uses-permissions from the manifest, I get the expected permission denial errors when trying to use my app. However, I still receive the ACTION_BOOT_COMPLETED intent broadcasted upon boot. Any suggestions?

This would appear to be a bug in Android. I can reproduce the problem on ordinary Nexus One and Nexus S hardware. I have filed a bug report on it.

Related

BOOT_COMPLETED sporadically not sent on bootup

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);
}
}

BOOT_COMPLETED not received

I have created an Android application that should start a service after BOOT.
It works just fine on a Nexus 5 phone, but I can not make it work on a Huawei tablet (Mediapad X2). I am using Android 5.0 / API 21.
The manifest has the proper permissions/intents according to the guidelines.
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<receiver
android:name=".BootBroadcast"
android:enabled="true"
android:exported="true"
android:label="BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
I search SO for similar issues (BOOT_COMPLETED not working Android) and have added the QUICKBOOT_POWERON intent, as well as the WAKE_LOCK permission but nothing has changed.
The Broadcast Receiver is just starting the service
public class BootBroadcast extends BroadcastReceiver {
private static final String TAG = "GrandUnion-Boot";
#Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "Boot_Completed RECEIVED");
try{
context.startService(new Intent(context,MyService.class));
Log.i(TAG, "Boot Completed - start service");
}catch(Exception e){
Log.e(TAG,e.toString());
}
}
}
After long researches I find out, that some devices have their own startup manager. And Huawei Mediapad one of those, so:
Go to the settings of device
Find startup manager
Allow app to start.
In case your device does not have a startup/boot manager, try checking the app manager. On Lenovo's VibeUI, the app manager has an option "restrict launch",which when enabled prevents the app from receiving BOOT_COMPLETED intent.

android.intent.action.BOOT_COMPLETED not working with nexus 4

I want to use android.intent.action.BOOT_COMPLETED for starting my service at start but I am not receiving its broadcast in nexus 4. Its working fine with Samsung phones.
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Also I have given permissions
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Receiver file:
public class BootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "boot completed", Toast.LENGTH_SHORT).show();
Log.d("Boot Completed", "Boot completed received");
}
}
I am not receiving BOOT_COMPLETED intent.
ITS WORKING FINE WITH SAMSUNG MODELS BUT NOT WORKING WITH NEXUS 4.
I AM USING ANDROID STUDIO.
PLEASE HELP.
This works for me, in my onReceive
String action = intent.getAction();
if(action.equals(Intent.ACTION_BOOT_COMPLETED)){
//do stuff
}
You will be only receiving BOOT_COMPLETED broadcast if user runs your app at least once. This is a security measure since Android 3.1.
This does not affect system applications, but I suppose you are not writing one...
Does that help?

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 correctly filter Package replaced broadcast

I am trying to catch the package replaced broadcast for my app and only my app, but for some reason in my reciever I am the broadcast for every app that is updated. I thought you only needed to set the intent filter in the manifest file to your app, but maybe I am wrong?
Here's my code(manifest):
<receiver android:name=".UpdateReciever">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" android:path="com.my.app" />
</intent-filter>
</receiver>
Reciever:
public class AppUpdateReciever extends BroadcastReceiver {
#Override
public void onReceive(Context con, Intent intent) {
//code..
}
}
Add this to your onReceive method:
if (intent.getDataString().contains("com.my.app")){
...
}
EDIT:
Note that registering for ACTION_PACKAGE_REPLACED causes your app to be started up every time any app is updated, if it wasn't already open. I don't know how to avoid this before API 12, but in API 12 you can register for ACTION_MY_PACKAGE_REPLACED so you don't have to filter the intent and your app won't be started unnecessarily by other apps being updated.
Alternately, if your code is in a library that's included in multiple apps, or if you just want something that can be copy/pasted between apps without edits:
int intentUid = intent.getExtras().getInt("android.intent.extra.UID");
int myUid = android.os.Process.myUid();
if (intentUid == myUid)
{
...
}

Categories

Resources