Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions app/src/main/java/us/shandian/giga/ui/adapter/MissionAdapter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package us.shandian.giga.ui.adapter;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_GRANT_PREFIX_URI_PERMISSION;
import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
import static android.content.Intent.createChooser;
import static us.shandian.giga.get.DownloadMission.ERROR_CONNECT_HOST;
Expand Down Expand Up @@ -70,12 +69,12 @@

import java.io.File;
import java.net.URI;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.text.DateFormat;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
Expand Down Expand Up @@ -348,20 +347,28 @@ private void viewWithFileProvider(Mission mission) {

String mimeType = resolveMimeType(mission);

if (BuildConfig.DEBUG)
if (BuildConfig.DEBUG) {
Log.v(TAG, "Mime: " + mimeType + " package: " + BuildConfig.APPLICATION_ID + ".provider");
}

// Create the intent to view/play the downloaded file
Intent viewIntent = new Intent(Intent.ACTION_VIEW);
viewIntent.setDataAndType(resolveShareableUri(mission), mimeType);
viewIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
viewIntent.addFlags(FLAG_GRANT_PREFIX_URI_PERMISSION);

Intent chooserIntent = createChooser(viewIntent, null);
chooserIntent.addFlags(FLAG_ACTIVITY_NEW_TASK);
chooserIntent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
chooserIntent.addFlags(FLAG_GRANT_PREFIX_URI_PERMISSION);
// Attach the file URI and its corresponding MIME type
viewIntent.setDataAndType(resolveShareableUri(mission), mimeType);

ShareUtils.openIntentInApp(mContext, chooserIntent);
/*
* Note: We pass viewIntent directly to openIntentInApp instead of using Intent.createChooser().
* On modern Android versions, wrapping an intent with createChooser() prevents the
* system from showing the "Always" option, forcing the user to pick an app every time.
* By removing the chooser, we allow the OS to respect and save the user's default app preference.
*/
viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
viewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
viewIntent.addFlags(Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);

// Open the intent directly to trigger the standard system resolver
ShareUtils.openIntentInApp(mContext, viewIntent);
}

private void shareFile(Mission mission) {
Expand Down
Loading