title: I cannot run any code on boot completed on Android
body: <p>I researched in order to find out the way to make my app do something on device boot. I tried to do the same but it does not seem to work. I tried with several methods but I am finding some unexpected problems.
  Here is my manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.ignacio.dailynotification"&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  &lt;!-- Keeps the processor from sleeping when a message is received. --&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".MainActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;activity
          android:name=".SettingsActivity"
          android:label="@string/title_activity_settings"
          android:parentActivityName=".MainActivity"&gt;
          &lt;meta-data
              android:name="android.support.PARENT_ACTIVITY"
              android:value=".MainActivity" /&gt;
      &lt;/activity&gt;
  
      &lt;receiver
          android:name=".BootCompletedReceiver"
          android:enabled="true"
          android:exported="true"
          android:permission="android.permission.RECEIVE_BOOT_COMPLETED" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>And here is my broadcast receiver BootCompletedReceiver:</p>
  
  <pre><code>public class BootCompletedReceiver extends BroadcastReceiver {
  private static final String LOG_TAG = BootCompletedReceiver.class.getSimpleName();
  @Override
  public void onReceive(Context context, Intent intent) {
  
      String action = intent.getAction();
  
      String message = "BootCompletedReceiver onReceive, action is " + action;
  
      Toast.makeText(context, message, Toast.LENGTH_LONG).show();
  
      Log.d(LOG_TAG, action);
  
      if(Intent.ACTION_BOOT_COMPLETED.equals(action))
      {
          Toast.makeText(context, "phone restarted",    Toast.LENGTH_SHORT).show();
          Log.d(LOG_TAG,"phone restarted");
  
      }
  }
  }
  </code></pre>
  
  <p>Now I am getting this output in my logcat when searching for 'bootcompleted':</p>
  
  <pre><code>2019-09-20 07:52:56.776 1867-2017/? I/keyguard:     AsusSlideshowManager:queryLocalList cursor null mBootCompleted:false mRetryQuery:0
  2019-09-20 07:52:57.291 1867-2017/? I/keyguard: AsusSlideshowManager:queryLocalList cursor null mBootCompleted:false mRetryQuery:0
  2019-09-20 07:52:58.303 1867-2017/? I/keyguard: AsusSlideshowManager:queryLocalList cursor null mBootCompleted:false mRetryQuery:0
  2019-09-20 07:53:00.491 1867-1867/? I/keyguard: AsusWeatherDataMonitor: :onBootCompleted
  2019-09-20 07:53:16.910 2144-2144/? E/VvmBootCompletedRcvr: phone account ComponentInfo{com.android.phone/com.android.services.telephony.TelephonyConnectionService}, [e0184adedf913b076626646d3f52c3b49c39ad6d], UserHandle{0} has invalid subId -1
  2019-09-20 07:53:17.326 1435-2416/? I/ActivityManager: Start proc 4147:com.android.vending/u0a47 for broadcast com.android.vending/com.google.android.finsky.boothandler.BootCompletedReceiver duration: 14
  2019-09-20 07:53:19.716 1435-2027/? I/ActivityManager: Start proc    4313:com.asus.dm/1000 for broadcast com.asus.dm/.BootCompletedReceiver duration: 21
  2019-09-20 07:53:19.836 4313-4313/? D/DMC-&gt;BootCompletedReceiver: ===== BCReceiver: Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 cmp=com.asus.dm/.BootCompletedReceiver (has extras) }
  2019-09-20 07:53:19.935 4313-4313/? D/DMC-&gt;BootCompletedReceiver: check fota update status.
  2019-09-20 07:53:19.935 4313-4313/? D/DMC-&gt;BootCompletedReceiver: check unfinished dm session.
  2019-09-20 07:53:19.935 4313-4313/? D/DMC-&gt;BootCompletedReceiver: check is need resume DL.
  2019-09-20 07:53:19.935 4313-4313/? D/DMC-&gt;BootCompletedReceiver: ===== over 18 month, no fota polling @receiveBootComplete()
  2019-09-20 07:53:19.936 4313-4313/? D/DMC-&gt;BootCompletedReceiver: NextPollingInterval: Long.MAX_VALUE
  2019-09-20 07:53:19.936 4313-4313/? D/DMC-&gt;BootCompletedReceiver: **NOT** Start DM Service
  2019-09-20 07:53:19.937 4313-4313/? D/DMC-&gt;BootCompletedReceiver: exit onReceive
  2019-09-20 07:53:19.938 4313-4313/? I/ActivityThread: Performing receive of Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 cmp=com.asus.dm/.BootCompletedReceiver (has extras) }: app=com.asus.dm.DMApp@a04c4e4, appName=com.asus.dm, pkg=com.asus.dm, comp={com.asus.dm/com.asus.dm.BootCompletedReceiver}, dir=/system/app/DMClient/DMClient.apk, duration=102
  2019-09-20 07:53:21.696 4423-4423/? D/FirmwareManager: Booted - onBootCompleted, check for PAD EC and Camera ISP
  2019-09-20 07:53:24.792 1435-2706/? I/ActivityManager: Start proc 4686:com.asus.userfeedback/u0a108 for broadcast com.asus.userfeedback/.BootCompletedBroadcastReceiver duration: 18
  2019-09-20 07:53:25.721 1435-1435/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1357 android.content.ContextWrapper.startService:620 android.content.ContextWrapper.startService:620 com.dsi.ant.server.AntService.startService:129 com.dsi.ant.server.startup.BootCompletedReceiver.onReceive:41 
  2019-09-20 07:53:26.169 1435-2416/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 (has extras) } to com.google.android.apps.docs/com.google.android.libraries.internal.growth.growthkit.inject.GrowthKitBootCompletedBroadcastReceiver requires android.permission.RECEIVE_BOOT_COMPLETED due to sender null (uid 1000)
  2019-09-20 07:53:34.828 5190-5190/? W/GrowthKit: Failed to get GrowthKitJobScheduler in GrowthKitBootCompletedBroadcastReceiver So GrowthKit failed to schedule jobs after package replaced / boot completed.
  java.lang.NullPointerException: Unable to get GrowthKit Component from host app.
      at com.google.android.libraries.internal.growth.growthkit.inject.GrowthKit.get(GrowthKit.java:43)
      at com.google.android.libraries.internal.growth.growthkit.inject.GrowthKitBootCompletedBroadcastReceiver.onReceive(GrowthKitBootCompletedBroadcastReceiver.java:29)
      at android.app.ActivityThread.handleReceiver(ActivityThread.java:3044)
      at android.app.ActivityThread.-wrap18(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1561)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:159)
      at android.app.ActivityThread.main(ActivityThread.java:6139)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  2019-09-20 07:53:40.272 2820-5535/? I/constellation: [intent_handler] Received onBootCompleted intent
  2019-09-20 07:53:43.700 2254-5354/? I/NetRec: [145] BootCompletedOrAppUpdatedIntentOperation.onHandleIntent: onBootCompleted()
  2019-09-20 07:53:43.948 2254-5354/? I/NetRec: [145] BootCompletedOrAppUpdatedIntentOperation.onHandleIntent: Scheduling CleanupDatabaseTask
  2019-09-20 07:53:46.769 1435-1453/? I/ActivityManager: Start proc 5946:org.simalliance.openmobileapi.service/1000 for broadcast org.simalliance.openmobileapi.service/.SmartcardServiceBootCompletedBroadcastReceiver duration: 17
  </code></pre>
  
  <p>I think maybe I am getting the broadcast properly received but my app cannot do anything beyond that or so it seems. </p>
  
  <p>Thanks in advance for your help.
  Thanks in advance for your help.</p>