Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Util function for opening activity in other app via <code>uri</code>.
- * If there is no app which can handle this uri, this method will show toast error message to
- * user and won't attempt to start activity (which would result in ActivityNotFoundException).
- */
- public static void openInOtherApp(@NonNull Context context, @NonNull Uri uri) {
- Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- /* VERIFY THERE IS APP THAT CAN HANDLE THIS INTENT */
- List<ResolveInfo> activities = context.getPackageManager().queryIntentActivities(intent, 0);
- boolean isSafeIntent = activities.size() > 0;
- if (isSafeIntent) {
- context.startActivity(intent);
- } else {
- Toast.makeText(context, R.string.no_app_can_handle_intent, Toast.LENGTH_SHORT).show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement