Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The other answers look good, but I thought I'd wrap everything up into one complete answer.</p> <p>You need the following in your <code>AndroidManifest.xml</code> file:</p> <ol> <li><p>In your <code>&lt;manifest&gt;</code> element:</p> <pre><code>&lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt; </code></pre></li> <li><p>In your <code>&lt;application&gt;</code> element (be sure to use a fully-qualified [or relative] class name for your <code>BroadcastReceiver</code>):</p> <pre><code>&lt;receiver android:name="com.example.MyBroadcastReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>(you don't need the <code>android:enabled</code>, <code>exported</code>, etc., attributes: the Android defaults are correct)</p> <p>In <code>MyBroadcastReceiver.java</code>:</p> <pre><code>package com.example; public class MyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent startServiceIntent = new Intent(context, MyService.class); context.startService(startServiceIntent); } } </code></pre></li> </ol> <p>From the original question:</p> <ul> <li>it's not clear if the <code>&lt;receiver&gt;</code> element was in the <code>&lt;application&gt;</code> element</li> <li>it's not clear if the correct fully-qualified (or relative) class name for the <code>BroadcastReceiver</code> was specified</li> <li>there was a typo in the <code>&lt;intent-filter&gt;</code></li> </ul>
 

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