title: REQUEST_IGNORE_BATTERY_OPTIMIZATIONS how to do it right
body: <p>I have <code>IntentService</code> task in foreground mode, but in Android M+ the task stops in Doze mode. I read Google banned if the app uses intent to set themselves in whitelist. But if I use permission and check GRANT or DENIED, I get the granted result, but nothing happen. I don't see my app in whitelist. How can I add the app in whitelist without banned? (I added permission in <code>AndroidManifest.xml</code>)</p>
  
  <pre class="lang-java prettyprint-override"><code>if(Build.VERSION.SDK_INT&gt;=23){
      int permissionCheck= ContextCompat
                      .checkSelfPermission(this, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
  
      if(permissionCheck == PackageManager.PERMISSION_DENIED){
  
          //Should we show an explanation
          if(ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)){
              //Show an explanation
              final String message = "";
               Snackbar.make(coordinatorLayoutView,message,Snackbar.LENGTH_LONG)
                       .setAction("GRANT", new View.OnClickListener() {
                           @Override
                           public void onClick(View v) {
                               ActivityCompat.requestPermissions(MainActivity.this, new String[]{ Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS }, PERMISSION_REQUEST_CODE);
                           }
                       })
                       .show();
  
                  }else{
                      //No explanation need,we can request the permission
                      ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS }, PERMISSION_REQUEST_CODE);
                  }
              }
          }
  </code></pre>