title: Android READ PHONE STATE permission
body: <p>I'm working on a small app that requires READ_PHONE_STATE permission. I added the permission request on my <code>manifest.xml</code> as such</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.mobile.stoq.stoqpay"&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;application
      ...
  </code></pre>
  
  <p>However while reading on it I found I had to do an actual request to the user to acquire that permission, so I tried to do so with the following snippet</p>
  
  <pre><code>public class ValidationActivity extends AppCompatActivity {
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_validation);
          //TODO: Fix this permission request. It sort of works but not really
          int REQUEST_RPS = 0;
          if (ContextCompat.checkSelfPermission(ValidationActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
              ActivityCompat.requestPermissions(ValidationActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_RPS);
          }
  
          List&lt;UserModel&gt; listOfUser = StoneStart.init(this);
  
          if (listOfUser == null) {
  
              List&lt;String&gt; stoneCodeToActiveList = new ArrayList&lt;&gt;();
              String STONE_PRODUCTION_KEY = "846873720";
              stoneCodeToActiveList.add(STONE_PRODUCTION_KEY);
  
              ActiveApplicationProvider activeApplicationProvider = new ActiveApplicationProvider(this, stoneCodeToActiveList);
              activeApplicationProvider.setDialogMessage("Activating");
              activeApplicationProvider.setDialogTitle("Please wait");
              activeApplicationProvider.setWorkInBackground(false);
              activeApplicationProvider.setConnectionCallback(new StoneCallbackInterface() {
                  public void onSuccess() {
                      Toast.makeText(getApplicationContext(), "Activation successful", Toast.LENGTH_SHORT).show();
                      continueApplication();
                  }
  
                  public void onError() {
                      Toast.makeText(getApplicationContext(), "Activation failed", Toast.LENGTH_SHORT).show();
                  }
              });
              activeApplicationProvider.execute();
          } else {
              continueApplication();
  
          }
      }
  
      private void continueApplication() {
  
          int SPLASH_DISPLAY_LENGTH = 3500;
          new Handler().postDelayed(new Runnable() {
              public void run() {
  
                  Intent mainIntent = new Intent(ValidationActivity.this, MainActivity.class);
                  ValidationActivity.this.startActivity(mainIntent);
                  ValidationActivity.this.finish();
              }
          }, SPLASH_DISPLAY_LENGTH);
      }
  }
  </code></pre>
  
  <p>When my app runs though it will either crash or freeze, and after I restart it I have the correct permissions and it works nicely. This is what logcat shows me:</p>
  
  <pre><code>03-13 19:49:57.938 6682-6714/com.mobile.stoq.stoqpay W/System.err: java.lang.SecurityException: getDeviceId: Neither user 10068 nor current process has android.permission.READ_PHONE_STATE.
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at android.os.Parcel.readException(Parcel.java:1620)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at android.os.Parcel.readException(Parcel.java:1573)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:4207)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:706)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at stone.providers.ActiveApplicationProvider.doInBackground(ActiveApplicationProvider.java:102)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
  03-13 19:49:57.954 6682-6714/com.mobile.stoq.stoqpay W/System.err:     at java.lang.Thread.run(Thread.java:818)
  </code></pre>
  
  <p>What am I doing wrong? How may I fix this?</p>