Start washing after reboot

I have a GPS service that receives a GPS position every 60 seconds. It works fine, but after rebooting the phone it does nothing. I tried adding this to a BroadcastReceiver , which works after a reboot, but nothing happens. Any help would be great; I just need to load my intentions after reboot.

 //Start intents after reboot if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { context.startService(new Intent(context, DashboardActivity.class)); } 

GPSActivity.java

 public int onStartCommand(Intent intent, int flags, int startId) { //Toast.makeText(getBaseContext(), "Service Started", Toast.LENGTH_SHORT).show(); final Runnable r = new Runnable() { public void run() { Log.v("GPS_TRACKER", "Run Start"); location(); handler.postDelayed(this, 60000); } }; handler.postDelayed(r, 60000); return START_STICKY; } 

manifest

 <!-- GPS Activity --> <service android:enabled="true" android:name=".GPSActivity"> <intent-filter> <action android:name="com.ni.androidtrack.GPSActivity"/> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </service> <!-- Also permission for RECEIVE_BOOT_COMPLETED --> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
+1
source share
3 answers

In your manifest:

 <service android:exported="false" android:name=".service.YourService" android:enabled="true"></service> <receiver android:name=".service.YourBootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiver> 

Also add permission to the manifest:

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 

YourBootReceiver:

 public class YourBootReceiver extends BroadcastReceiver { @Override public void onReceive(Context arg0, Intent arg1) { Intent serviceIntent = new Intent(arg0, YourService.class); arg0.startService(serviceIntent); } 
+3
source

You must add RECEIVE_BOOT_COMPLETED permission to the manifest file to receive a notification:

 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
+1
source
 if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { context.startService(new Intent(context, GPSActivity.class)); } 
0
source

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


All Articles