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?
Related
I noticed that my Huawei test device (Huawei P20) does not detect action BOOT_COMPLETED, while other test devices do (Samsung ...). I know that adding my application under-protected apps (Manual Mode)
would solve my problem, but my end users do not know how to add application under-protected apps.
Is there any way to detect system BOOT without adding application under-protected apps (Manual mode)?
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".recivers.BootBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
Receiver:
public class BootBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "BootBroadcastReceiver";
#Override
public void onReceive(Context context, Intent intent) {
String action = intent . getAction ();
if (action != null && action.equals(Intent.ACTION_BOOT_COMPLETED)) {
Toast.makeText(context, "BOOT", Toast.LENGTH_LONG).show();
Log.e(TAG, "BOOT");
}
}
}
I also had that problem, what happens is that huawei has a layer where it controls the applications that implies restarting them.
You have to go to Settings -> Battery -> Automatic start
As they mention it here
Intent BOOT_COMPLETED not working on Huawei device
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);
}
}
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.
I'm trying to implement a broadcast receiver that catch the boot complete event.
I put the permission in the manifet
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
I put the intent filter after the receiver tag in the manifest (the class file is in the receivers package)
<receiver android:name=".receivers.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.REBOOT" />
</intent-filter>
</receiver>
and finally I declared the receiver class. The class should load some data from the database and set an alarm. However to check if it works I've put a Toast but it's not displayed and a vibra.
public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent callingIntent) {
Vibrator vibrator=(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(5000);
Toast.makeText(context, "BOOT RECEIVED", Toast.LENGTH_LONG).show();
}
}
Anyone knows why please?
All just installed applications gets into the stopped state (the actual file is /data/system/packages-stopped.xml)
Starting from Android 3.1, the system's package manager keeps track of applications that are in a stopped state. See this link: android 3.1 launch control.
Intent with action android.intent.action.BOOT_COMPLETED has a FLAG_EXCLUDE_STOPPED_PACKAGES extra flag. It means that all stopped applications will not receive the BOOT_COMPLETED events.
To get your application out of the stopped state, start it manually just after installation. Then you can do a reboot and will see the expected Toast.
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.