List of utility methods to do Intent Check
String | getAction(Intent intent) get Action if (intent != null) { return intent.getAction(); return null; |
boolean | isActionEquals(Intent intent, String expected) is Action Equals if (expected == null) { return false; } else { String action = getAction(intent); return action != null && action.equals(expected); |
boolean | isActionEquals(Intent intent, String expected) is Action Equals if (expected == null) { return false; } else { String action = getAction(intent); return action != null && action.equals(expected); |
boolean | isBroadcastSafe(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); |
boolean | isIntentAvailable(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; |
boolean | isIntentSafe(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); |
PendingIntent | genPendingBroadcast(Context context, int requestCode, Intent broadcastIntent) gen Pending Broadcast PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
requestCode, broadcastIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent;
|
boolean | isIntentAvailable(@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; |
boolean | isIntentAvailable(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; ... |
boolean | isDownloadsDocument(Uri uri) is Downloads Document return "com.android.providers.downloads.documents".equals(uri .getAuthority()); |