Skip to content

Commit 2ee5f99

Browse files
authored
Merge pull request TeamNewPipe#12934 from TobiGr/fix/open-download
Fix insufficient permissions on opening downloaded streams
2 parents 3c0e6ad + 3ffd194 commit 2ee5f99

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static android.content.Intent.FLAG_GRANT_PREFIX_URI_PERMISSION;
44
import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
5+
import static android.content.Intent.createChooser;
56
import static us.shandian.giga.get.DownloadMission.ERROR_CONNECT_HOST;
67
import static us.shandian.giga.get.DownloadMission.ERROR_FILE_CREATION;
78
import static us.shandian.giga.get.DownloadMission.ERROR_HTTP_NO_CONTENT;
@@ -349,11 +350,15 @@ private void viewWithFileProvider(Mission mission) {
349350
if (BuildConfig.DEBUG)
350351
Log.v(TAG, "Mime: " + mimeType + " package: " + BuildConfig.APPLICATION_ID + ".provider");
351352

352-
Intent intent = new Intent(Intent.ACTION_VIEW);
353-
intent.setDataAndType(resolveShareableUri(mission), mimeType);
354-
intent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
355-
intent.addFlags(FLAG_GRANT_PREFIX_URI_PERMISSION);
356-
ShareUtils.openIntentInApp(mContext, intent);
353+
Intent viewIntent = new Intent(Intent.ACTION_VIEW);
354+
viewIntent.setDataAndType(resolveShareableUri(mission), mimeType);
355+
viewIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
356+
viewIntent.addFlags(FLAG_GRANT_PREFIX_URI_PERMISSION);
357+
358+
Intent chooserIntent = createChooser(viewIntent, null);
359+
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | FLAG_GRANT_READ_URI_PERMISSION);
360+
361+
ShareUtils.openIntentInApp(mContext, chooserIntent);
357362
}
358363

359364
private void shareFile(Mission mission) {
@@ -364,8 +369,7 @@ private void shareFile(Mission mission) {
364369
shareIntent.putExtra(Intent.EXTRA_STREAM, resolveShareableUri(mission));
365370
shareIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
366371

367-
final Intent intent = new Intent(Intent.ACTION_CHOOSER);
368-
intent.putExtra(Intent.EXTRA_INTENT, shareIntent);
372+
final Intent intent = createChooser(shareIntent, null);
369373
// unneeded to set a title to the chooser on Android P and higher because the system
370374
// ignores this title on these versions
371375
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {

0 commit comments

Comments
 (0)