title: Broadcast receiver android.intent.action.BOOT_COMPLETED not working
body: <p>I am trying to start service on Boot completion, After doing lot digging I have found nothing. </p>
  
  <p>Very first approach that I have tried was <a href="https://stackoverflow.com/a/20441442/5476209">this</a>, I found this approach in most answers, but it doesn't work. </p>
  
  <p>Then I have found that this approach is not working on 3.1+ from <a href="https://stackoverflow.com/a/19856367/5476209">here</a></p>
  
  <p>I have also seen this, <a href="https://developer.android.com/about/versions/android-3.1.html#launchcontrols" rel="noreferrer">https://developer.android.com/about/versions/android-3.1.html#launchcontrols</a></p>
  
  <p>and used <strong>FLAG_INCLUDE_STOPPED_PACKAGES</strong> also in my code.I have referred this approach from <a href="https://stackoverflow.com/q/9783704/5476209">here</a>.</p>
  
  <h2>AndroidMenifest</h2>
  
  <p>
  </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;uses-permission android:name="android.permission.REAL_GET_TASKS"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/security"
      android:label="@string/app_name"
      android:supportsRtl="true"&gt;
  
      &lt;receiver android:name="com.reversebits.projects.app.easyerase.receiver.BootReceiver"
          android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
          android:enabled="true"
          android:exported="true"&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
          &lt;/intent-filter&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="myReceiver" /&gt;
          &lt;/intent-filter&gt;
  
      &lt;/receiver&gt;
  
      &lt;activity
          android:name=".Home"
          android:theme="@style/AppTheme"&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;service
          android:name=".services.BootService"
          android:enabled="true"&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="com.reversebits.projects.app.easyerase.services.BootService"/&gt;
          &lt;/intent-filter&gt;
  
      &lt;/service&gt;
  
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <h2>BootReciever</h2>
  
  <pre><code>public class BootReceiver extends BroadcastReceiver {
  
      public BootReceiver() {
      }
      @Override
      public void onReceive(Context context, Intent intent) {
  
          if(intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED))
          {
              context.startService(new Intent(context, BootService.class));
          }
      }
  }
  </code></pre>
  
  <h2>BootService</h2>
  
  <pre><code>public class BootService extends Service {
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          //TODO do something useful Recommended by google instead of onStart()
          return Service.START_STICKY;
      }
  
      @Override
      public void onCreate() {
          super.onCreate();
          loopThread();
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
      }
  
  
      void loopThread() {
          new Thread(new Runnable() {
              @Override
              public void run() {
                  AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
                  switch (am.getRingerMode()) {
                      case AudioManager.RINGER_MODE_SILENT:
                          Log.e("MyApp", "Silent mode");
                          break;
                      case AudioManager.RINGER_MODE_VIBRATE:
                          Log.e("MyApp", "Vibrate mode");
                          break;
                      case AudioManager.RINGER_MODE_NORMAL:
                          Log.e("MyApp", "Normal mode");
                          break;
  
                  }
                  try {
                      Thread.sleep(2000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
                  loopThread();
              }
          }).start();
      }
  }
  </code></pre>
  
  <p><strong>Code works perfect and i got all logs when service is starting from activity, but on Boot complete, it is not working</strong></p>
  
  <p><strong>Note:</strong> 
  I have read almost all related answers and on some answers,I have also read comments and I know almost all related things, so please do not provide me other links, as  have seen most of them already, I need the perfect solution. Any help is appreciated.</p>