title: Android permission at runtime with external class
body: <p>I apologize for my English. </p>
  
  <p>I try for a few hours to create a class that allows a request for permission to run time. I think the basic system makes the code unreadable if you have permission requested in several different activity. </p>
  
  <p>So I created the following class</p>
  
  <pre><code>public class PermissionsHelper {
  
      public interface PermissionHelperListener{
          void accepted();
  
          void rejected();
      }
  
      private static  PermissionsHelper mInstance;
      private static  AppCompatActivity mContext;
      public static  ArrayList&lt;PermissionHelperListener&gt; permissionHelperListeners;
  
      public static PermissionsHelper getInstance(AppCompatActivity context){
          mContext = context;
          if(mInstance == null){
              mInstance = new PermissionsHelper();
          }
          return mInstance;
      }
  
      public void requestPermissions(String perm, PermissionHelperListener permissionHelperListener){
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
              if (mContext.checkSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) {
                  int index = permissionHelperListeners.size();
                  permissionHelperListeners.add(permissionHelperListener);
                  mContext.requestPermissions(new String[]{perm}, index);
              }
          }
      }
  
      public void requestPermissions (String[] perms, PermissionHelperListener permissionHelperListener){
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
              int index = permissionHelperListeners.size();
              permissionHelperListeners.add(permissionHelperListener);
              mContext.requestPermissions(perms, index);
          }
      }
  
      public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
          if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
              permissionHelperListeners.get(requestCode).accepted();
          } else {
              permissionHelperListeners.get(requestCode).rejected();
          }
          permissionHelperListeners.remove(requestCode);
      }
  
  }
  </code></pre>
  
  <p>I call my class in <code>onRequestPermissionsResult</code>like this</p>
  
  <pre><code>@Override
  public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
      PermissionsHelper.getInstance(this).onRequestPermissionsResult(requestCode, permissions, grantResults);
  }
  </code></pre>
  
  <p>everything is right until now. but when I use <code>requestPermissions</code> in my activity there is always the warning to check permission. I used <code>@SuppressWarnings("ALL")</code> and it work but I do not really like it. is there an other way to remove this warning or ask permissions with a callback like this ? </p>
  
  <p>Thanks a lot</p>