Application startup on boot completed

Below is the code that I use to run the application when the device is turned on.

public class BootReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Log.i("BootReceiver","intent received"); Intent myIntent = new Intent(context, ACT_Home.class); myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(myIntent); } } 

and in the manifest (like <Application> child):

 <receiver android:name="host.alarmmanager.BootReceiver"> <intent-filter > <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver> 

Permissions within the manifest are as follows:

 <uses-permission android:name="android.permission.INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.VIBRATE" /> <uses-feature android:name="android.hardware.camera"/> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> 

This works fine on Android 3.2.2, but if I try the same application on Android 4.0.3, the broadcast receiver will not get anything. Also, the first line inside the onReceive method onReceive not executed. Why is this happening?

+4
source share
3 answers
 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

This is what you should use in the android manifest

+7
source

Try this, although your code seems great! The following works for me.

  <!-- Receivers --> <receiver android:enabled="true" android:name="host.alarmmanager.BootReceiver" 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> 
+2
source

Make sure that you do not restart the phone by selecting the restart option in the power menu.

Android unusually has 2 different resolutions.

1.Reboot

2. Download completion

So, turn off the phone first, and then turn it on again after a few seconds!

Hope this helps! (Y)

0
source

Source: https://habr.com/ru/post/1502762/


All Articles