I know that we can open a file normally from internal storage like this:

```
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "my_file.zip");
Uri uri = (FileProvider.getUriForFile(context, AUTHORITY_OPEN_FILE, file)
Intent intent = new Intent(Intent.ACTION_VIEW)
            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            .setData(uri);
context.startActivity(intent);

```

But I do not know on how to open a file from SD card, which we can pick using `DocumentFile` like this:

```
Uri uri = new Uri.Builder()
            .scheme("content")
            .authority("com.android.externalstorage.documents")
            .appendPath("document")
            .appendPath(directory)
            .appendPath(fileName)
            .build();
DocumentFile documentFile = DocumentFile.fromSingleUri(context, uri);

```

I tried the following snippet:

```
Uri uri = documentFile.getUri();
Intent intent = new Intent(Intent.ACTION_VIEW)
            .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            .setData(uri);
context.startActivity(intent);

```

But resulting error:

```
 Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW dat=content://com.android.externalstorage.documents/document/6331-6132:/haxm-windows_r05_2.zip flg=0x10000001 cmp=com.google.android.gm/.browse.TrampolineActivity } from ProcessRecord{a0ed6d5 9894:com.mypackage.app/u0a169} (pid=9894, uid=10169) requires com.google.android.gm.permission.READ_GMAIL

```

I did grant for read and write external storage permissions:

```
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

```

And `Uri` permission as well:

```
int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
context.getContentResolver().takePersistableUriPermission(uri, takeFlags);

```

A file stored in SD card gives us a `Uri` like this, where `6331-6132` is identifier for our removable SD card:

```
content://com.android.externalstorage.documents/document/6331-6132:Folder/haxm-windows_r05_2.zip

```

I read so many posts on StackOverflow, but nothing help. Can you help me to solve this error? Thanks in advance.