Attempts to open a URI in another app via the system app chooser. @param context the app context @param uri the URI to open. @param failMessage string id: message to show in a toast when the system can't find an app to open with.
(@NonNull Context context, @NonNull Uri uri, @Nullable Integer failMessage)
| 205 | * @param failMessage string id: message to show in a toast when the system can't find an app to open with. |
| 206 | */ |
| 207 | public static void openUri(@NonNull Context context, @NonNull Uri uri, @Nullable Integer failMessage) |
| 208 | { |
| 209 | final Intent intent = new Intent(Intent.ACTION_VIEW); |
| 210 | intent.setData(uri); |
| 211 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 212 | intent.addCategory(Intent.CATEGORY_BROWSABLE); |
| 213 | |
| 214 | try |
| 215 | { |
| 216 | context.startActivity(intent); |
| 217 | } |
| 218 | catch (ActivityNotFoundException e) |
| 219 | { |
| 220 | if (failMessage != null) |
| 221 | Toast.makeText(context, context.getString(failMessage), Toast.LENGTH_LONG).show(); |
| 222 | Logger.e(TAG, "ActivityNotFoundException", e); |
| 223 | } |
| 224 | catch (AndroidRuntimeException e) |
| 225 | { |
| 226 | Logger.e(TAG, "AndroidRuntimeException", e); |
| 227 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 228 | context.startActivity(intent); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | private static boolean isHttpOrHttpsScheme(@NonNull String url) |
| 233 | { |