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.
How to start the application after boot complete in android version 3.1 and above?
-
05-12-2021 - |
سؤال
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.
المحلول
نصائح أخرى
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