Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately right now there is no reliable way to receive a broadcast event after your applicaiton has been installed, the <a href="http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_ADDED" rel="noreferrer">ACTION_PACKAGE_ADDED</a> Intent does not broadcast to the newly installed package.</p> <p>You will have to have a broadcast receiver class as well as your service in order to receive the <a href="http://developer.android.com/reference/android/content/Intent.html#ACTION_BOOT_COMPLETED" rel="noreferrer">ACTION_BOOT_COMPLETED</a> event. I would also recommend adding the <a href="http://developer.android.com/reference/android/content/Intent.html#ACTION_USER_PRESENT" rel="noreferrer">ACTION_USER_PRESENT</a> intent to be caught by that broadcast receiver, this requires Android 1.5 (minSDK=3), this will call your broadcast receiver whenever the user unlocks their phone. The last thing that you can do to try to keep your service running without having it easily be shut down automatically is to call <a href="http://developer.android.com/reference/android/app/Service.html#setForeground(boolean)" rel="noreferrer">Service.setForeground()</a> in your service onCreate to tell Android that your service shouldn't be stopped, this was added mainly for mp3 player type services that have to keep running but can be used by any service.</p> <p>Make sure you add the proper permissions for the boot_complete and user_present events in you manifest.</p> <p>Here is a simple class that you can use as a broadcast receiver for the events.</p> <pre><code>package com.snctln.util.WeatherStatus; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class WeatherStatusServiceReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if(intent.getAction() != null) { if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) || intent.getAction().equals(Intent.ACTION_USER_PRESENT)) { context.startService(new Intent(context, WeatherStatusService.class)); } } } }; </code></pre> <p>Good luck.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload