title: How to grant permissions to debugged android application?
body: <p>I have</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  </code></pre>
  
  <p>in my manifest but despite this my code tracing says that condition</p>
  
  <pre><code> if (ActivityCompat.checkSelfPermission(this,
                  android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp;
                  ActivityCompat.checkSelfPermission(this,
                          android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  </code></pre>
  
  <p>is <code>true</code>, i.e. both permissions are not granted.</p>
  
  <p>How to grant them then?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The logic of my application assumes not to REQUEST permissions. If they are granted, then it will work one way and if they are not granted, it will silently work without them.</p>
  
  <p>So, I need to grant them as if application was installed and permissions were granted during installation.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>I suspect the answer is somewhere in <code>Run/Debug configurations</code> of <code>Android Studio</code>.</p>
  
  <p>For example, I see the following line in console while debugging</p>
  
  <pre><code>adb shell pm install -r "MYPATH"
  </code></pre>
  
  <p>and also I see here <a href="https://developer.android.com/studio/command-line/adb.html#pm" rel="nofollow noreferrer">https://developer.android.com/studio/command-line/adb.html#pm</a> that there is an option of <code>-g</code> saying to "Grant all permissions listed in the app manifest".</p>
  
  <p>This is what I need to happen automatically.</p>