title: No permission grant found for UID and Uri error - Android Xiomi Mi
body: <p>I am trying to allow the user to upload an image from the gallery.</p>
  
  <p>On click of a button <code>pickFromGallery</code> - </p>
  
  <pre><code>   pickFromGallery.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
  
                      if (Build.VERSION.SDK_INT &lt; 19) {
                          Intent intent = new Intent();
                          intent.setType("image/jpeg");
                          intent.setAction(Intent.ACTION_GET_CONTENT);
                          startActivityForResult(Intent.createChooser(intent, "Select Picture"), 2124);
                      } else {
                          Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                          intent.addCategory(Intent.CATEGORY_OPENABLE);
                          intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                          intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
                          intent.setType("image/jpeg");
                          startActivityForResult(intent, 1);
                      }
                  }
              });
  </code></pre>
  
  <p>onActivityResult is implemented as so -</p>
  
  <pre><code>if (requestCode == 1) {
              Uri originalUri = null;
              if (Build.VERSION.SDK_INT &lt; 19) {
                  originalUri = data.getData();
              } else {
                  originalUri = data.getData();
                  final int takeFlags = data.getFlags()
                          &amp; (Intent.FLAG_GRANT_READ_URI_PERMISSION
                          | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  
                  try {
                      getContentResolver().takePersistableUriPermission(originalUri, takeFlags);
                  }
                  catch (SecurityException e){
                      e.printStackTrace();
                  }
              }
  </code></pre>
  
  <p>And I get the exception - </p>
  
  <pre><code>11-02 19:17:08.848 24468-24468/com.tinystep.app W/System.err: java.lang.SecurityException: No persistable permission grants found for UID 10268 and Uri 0 @ file:///storage/emulated/0/DCIM/Camera/IMG_20150612_222143.jpg
  </code></pre>
  
  <p>ONLY on Xiomi Mi (Android Version 5.0.2)</p>
  
  <p>My Manifest - </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  &lt;uses-permission android:name="com.android.launcher.permission.wINSTALL_SHORTCUT" /&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="com.google.android.c2dm.permission.RECEIVE" /&gt;
  &lt;uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" /&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;uses-permission android:name="android.permission.READ_CALENDAR" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_CALENDAR" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_SMS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_SMS" /&gt;
  &lt;uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/&gt;
  </code></pre>
  
  <p>I've looked at <a href="https://stackoverflow.com/q/25414352/3765646">How to persist permission in android API 19 (KitKat)?</a> and <a href="https://stackoverflow.com/q/33032902/3765646">No permission for UID to access URI error on Android Application</a> but the solutions mentioned there didn't work for me.</p>
  
  <p>Any help would be highly appreciated, I've been stuck on this for a while.</p>