Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use broadcast receiver if the power is connected or not and do your action accordingly.</p> <p><strong>For Power Connected:</strong></p> <pre><code>public class PowerConnected extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub if(intent.getAction().equalsIgnoreCase("android.intent.action.ACTION_POWER_CONNECTED")){ //Initialize your listener here... } } } </code></pre> <p>In your manifest file:</p> <pre><code>&lt;receiver android:name=".receiver.PowerConnected" &gt; &lt;intent-filter &gt; &lt;action android:name="android.intent.action.ACTION_POWER_CONNECTED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p><strong>When Power is Disconnected:</strong></p> <pre><code>public class PowerDisconnected extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { if(intent.getAction().equalsIgnoreCase("android.intent.action.ACTION_POWER_DISCONNECTED")){ //Do your task here... } } } </code></pre> <p>In your manifest file:</p> <pre><code>&lt;receiver android:name=".receiver.PowerDisconnected" &gt; &lt;intent-filter &gt; &lt;action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>Now you should use <code>service</code> and initialize your GPS there. When power is connected use <code>GPS_Provider</code> else use <code>network provider</code>.Use <code>wakelock</code> if needed. </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. 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