Android Utililty Methods Intent Check

List of utility methods to do Intent Check

Description

The list of methods to do Intent Check are organized into topic(s).

Method

StringgetAction(Intent intent)
get Action
if (intent != null) {
    return intent.getAction();
return null;
booleanisActionEquals(Intent intent, String expected)
is Action Equals
if (expected == null) {
    return false;
} else {
    String action = getAction(intent);
    return action != null && action.equals(expected);
booleanisActionEquals(Intent intent, String expected)
is Action Equals
if (expected == null) {
    return false;
} else {
    String action = getAction(intent);
    return action != null && action.equals(expected);
booleanisBroadcastSafe(Context context, Intent intent)
Purpose - Before triggering broadcast check if there is any registered receivers
if (context == null)
    return false;
PackageManager packageMgr = context.getPackageManager();
List<ResolveInfo> receivers = packageMgr.queryBroadcastReceivers(
        intent, 0);
return (receivers.size() > 0);
booleanisIntentAvailable(Context context, String action)
Indicates whether the specified action can be used as an intent.
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List<ResolveInfo> list = packageManager.queryIntentActivities(
        intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
booleanisIntentSafe(Context context, Intent intent)
Purpose - Before trigerring an implicit intent check if there is any registered activity
if (context == null)
    return false;
PackageManager packageMgr = context.getPackageManager();
List<ResolveInfo> activities = packageMgr.queryIntentActivities(
        intent, 0);
return (activities.size() > 0);
PendingIntentgenPendingBroadcast(Context context, int requestCode, Intent broadcastIntent)
gen Pending Broadcast
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
        requestCode, broadcastIntent,
        PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent;
booleanisIntentAvailable(@Nonnull Context context, @Nonnull String action)
Checks whether an action has a matching Intent in the current device
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
final List<ResolveInfo> list = packageManager
        .queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
booleanisIntentAvailable(Context context, String action)
is Intent Available
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List resolveInfo = packageManager.queryIntentActivities(intent,
        PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfo.size() > 0) {
    return true;
return false;
...
booleanisDownloadsDocument(Uri uri)
is Downloads Document
return "com.android.providers.downloads.documents".equals(uri
        .getAuthority());