mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
Changed: Show system chooser if failed to find activity to handle url
This commit is contained in:
@@ -14,6 +14,7 @@ import androidx.core.content.ContextCompat;
|
|||||||
|
|
||||||
import com.termux.shared.R;
|
import com.termux.shared.R;
|
||||||
import com.termux.shared.data.DataUtils;
|
import com.termux.shared.data.DataUtils;
|
||||||
|
import com.termux.shared.data.IntentUtils;
|
||||||
import com.termux.shared.file.FileUtils;
|
import com.termux.shared.file.FileUtils;
|
||||||
import com.termux.shared.logger.Logger;
|
import com.termux.shared.logger.Logger;
|
||||||
import com.termux.shared.models.errors.Error;
|
import com.termux.shared.models.errors.Error;
|
||||||
@@ -39,7 +40,11 @@ public class ShareUtils {
|
|||||||
chooserIntent.putExtra(Intent.EXTRA_INTENT, intent);
|
chooserIntent.putExtra(Intent.EXTRA_INTENT, intent);
|
||||||
chooserIntent.putExtra(Intent.EXTRA_TITLE, title);
|
chooserIntent.putExtra(Intent.EXTRA_TITLE, title);
|
||||||
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
try {
|
||||||
context.startActivity(chooserIntent);
|
context.startActivity(chooserIntent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.logStackTraceWithMessage(LOG_TAG, "Failed to open system chooser for:\n" + IntentUtils.getIntentString(chooserIntent), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,12 +93,13 @@ public class ShareUtils {
|
|||||||
*/
|
*/
|
||||||
public static void openURL(final Context context, final String url) {
|
public static void openURL(final Context context, final String url) {
|
||||||
if (context == null || url == null || url.isEmpty()) return;
|
if (context == null || url == null || url.isEmpty()) return;
|
||||||
try {
|
|
||||||
Uri uri = Uri.parse(url);
|
Uri uri = Uri.parse(url);
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
try {
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.logStackTraceWithMessage(LOG_TAG, "Failed to open the url \"" + url + "\"", e);
|
// If no activity found to handle intent, show system chooser
|
||||||
|
openSystemAppChooser(context, intent, context.getString(R.string.title_open_url_with));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -43,6 +43,7 @@
|
|||||||
|
|
||||||
<!-- ShareUtils -->
|
<!-- ShareUtils -->
|
||||||
<string name="title_share_with">Share With</string>
|
<string name="title_share_with">Share With</string>
|
||||||
|
<string name="title_open_url_with">Open URL With</string>
|
||||||
<string name="msg_storage_permission_not_granted">The storage permission not granted."</string>
|
<string name="msg_storage_permission_not_granted">The storage permission not granted."</string>
|
||||||
<string name="msg_file_saved_successfully">The %1$s file saved successfully at \"%2$s\""</string>
|
<string name="msg_file_saved_successfully">The %1$s file saved successfully at \"%2$s\""</string>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user