@Test public void deviceCanHandleIntent_whenActivityCanResolveIntent_shouldReturnTrue() throws Exception { Context context = mock(Context.class); PackageManager packageManager = mock(PackageManager.class); List<ResolveInfo> resolveInfos = new ArrayList<ResolveInfo>(); resolveInfos.add(new ResolveInfo()); stub(context.getPackageManager()).toReturn(packageManager); Intent specificIntent = new Intent(); specificIntent.setData(Uri.parse("specificIntent:")); stub(packageManager.queryIntentActivities(eq(specificIntent), eq(0))).toReturn(resolveInfos); assertThat(Intents.deviceCanHandleIntent(context, specificIntent)).isTrue(); }
public static boolean deviceCanHandleIntent(@NonNull final Context context, @NonNull final Intent intent) { try { final PackageManager packageManager = context.getPackageManager(); final List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); return !activities.isEmpty(); } catch (NullPointerException e) { return false; } }
Intents { public static boolean deviceCanHandleIntent(@NonNull final Context context, @NonNull final Intent intent) { try { final PackageManager packageManager = context.getPackageManager(); final List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); return !activities.isEmpty(); } catch (NullPointerException e) { return false; } } }
Intents { public static boolean deviceCanHandleIntent(@NonNull final Context context, @NonNull final Intent intent) { try { final PackageManager packageManager = context.getPackageManager(); final List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); return !activities.isEmpty(); } catch (NullPointerException e) { return false; } } private  Intents(); }
Intents { public static boolean deviceCanHandleIntent(@NonNull final Context context, @NonNull final Intent intent) { try { final PackageManager packageManager = context.getPackageManager(); final List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); return !activities.isEmpty(); } catch (NullPointerException e) { return false; } } private  Intents(); static void startActivity(@NonNull final Context context, @NonNull final Intent intent); static Intent getStartActivityIntent(@NonNull final Context context,
            @NonNull final Class clazz, @Nullable final Bundle extras); static boolean deviceCanHandleIntent(@NonNull final Context context,
            @NonNull final Intent intent); static boolean canHandleApplicationUrl(final Context context, final Uri uri); static boolean canHandleApplicationUrl(final Context context, final Uri uri,
            final boolean logError); static Intent intentForNativeBrowserScheme(@NonNull final Uri uri); static Intent intentForShareTweet(@NonNull final Uri uri); static void showMoPubBrowserForUrl(@NonNull final Context context,
            @NonNull Uri uri); static void launchActionViewIntent(Context context, @NonNull final Uri uri,
            @NonNull final String errorMessage); static void launchIntentForUserClick(@NonNull final Context context,
            @NonNull final Intent intent, @Nullable final String errorMessage); static void launchApplicationUrl(@NonNull final Context context,
            @NonNull final Uri uri); }
Intents { public static boolean deviceCanHandleIntent(@NonNull final Context context, @NonNull final Intent intent) { try { final PackageManager packageManager = context.getPackageManager(); final List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); return !activities.isEmpty(); } catch (NullPointerException e) { return false; } } private  Intents(); static void startActivity(@NonNull final Context context, @NonNull final Intent intent); static Intent getStartActivityIntent(@NonNull final Context context,
            @NonNull final Class clazz, @Nullable final Bundle extras); static boolean deviceCanHandleIntent(@NonNull final Context context,
            @NonNull final Intent intent); static boolean canHandleApplicationUrl(final Context context, final Uri uri); static boolean canHandleApplicationUrl(final Context context, final Uri uri,
            final boolean logError); static Intent intentForNativeBrowserScheme(@NonNull final Uri uri); static Intent intentForShareTweet(@NonNull final Uri uri); static void showMoPubBrowserForUrl(@NonNull final Context context,
            @NonNull Uri uri); static void launchActionViewIntent(Context context, @NonNull final Uri uri,
            @NonNull final String errorMessage); static void launchIntentForUserClick(@NonNull final Context context,
            @NonNull final Intent intent, @Nullable final String errorMessage); static void launchApplicationUrl(@NonNull final Context context,
            @NonNull final Uri uri);  }