List of usage examples for android.content Intent getCategories
public Set<String> getCategories()
From source file:at.wada811.utils.IntentUtils.java
public static String dump(Intent intent) throws JSONException { JSONObject json = new JSONObject(); json.put("action", intent.getAction()); if (intent.getCategories() != null) { JSONArray categories = new JSONArray(); for (String category : intent.getCategories()) { categories.put(category);/*ww w . j a va2s.c om*/ } json.put("category", categories); } json.put("type", intent.getType()); Bundle bundle = intent.getExtras(); if (bundle != null) { JSONObject extras = new JSONObject(); for (String key : bundle.keySet()) { extras.put(key, bundle.get(key)); } json.put("extras", extras); } return json.toString(4); }
From source file:cc.flydev.launcher.InstallShortcutReceiver.java
private static ShortcutInfo getShortcutInfo(Context context, Intent data, Intent launchIntent) { if (launchIntent.getAction() == null) { launchIntent.setAction(Intent.ACTION_VIEW); } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && launchIntent.getCategories() != null && launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); }//from w w w . j a va 2s. c om LauncherAppState app = LauncherAppState.getInstance(); return app.getModel().infoFromShortcutIntent(context, data, null); }
From source file:com.android.launcher4.InstallShortcutReceiver.java
private static ShortcutInfo getShortcutInfo(Context context, Intent data, Intent launchIntent) { if (launchIntent.getAction() == null) { launchIntent.setAction(Intent.ACTION_VIEW); } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && launchIntent.getCategories() != null && launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); }//from w ww. j a v a2 s. co m LauncherAppState app = LauncherAppState.getInstance(); ShortcutInfo info = app.getModel().infoFromShortcutIntent(context, data, null); info.title = ensureValidName(context, launchIntent, info.title); return info; }
From source file:com.googlecode.android_scripting.jsonrpc.JsonBuilder.java
private static JSONObject buildJsonIntent(Intent data) throws JSONException { JSONObject result = new JSONObject(); result.put("data", data.getDataString()); result.put("type", data.getType()); result.put("extras", build(data.getExtras())); result.put("categories", build(data.getCategories())); result.put("action", data.getAction()); ComponentName component = data.getComponent(); if (component != null) { result.put("packagename", component.getPackageName()); result.put("classname", component.getClassName()); }/*from w w w. j a va 2 s .c o m*/ result.put("flags", data.getFlags()); return result; }
From source file:com.android.launcher3.InstallShortcutReceiver.java
/** * Returns true if the intent is a valid launch intent for a shortcut. * This is used to identify shortcuts which are different from the ones exposed by the * applications' manifest file./* w w w. ja va 2s. c om*/ * * When DISABLE_ALL_APPS is true, shortcuts exposed via the app's manifest should never be * duplicated or removed(unless the app is un-installed). * * @param launchIntent The intent that will be launched when the shortcut is clicked. */ static boolean isValidShortcutLaunchIntent(Intent launchIntent) { if (launchIntent != null && Intent.ACTION_MAIN.equals(launchIntent.getAction()) && launchIntent.getComponent() != null && launchIntent.getCategories() != null && launchIntent.getCategories().size() == 1 && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && launchIntent.getExtras() == null && TextUtils.isEmpty(launchIntent.getDataString())) { return false; } return true; }
From source file:com.achep.base.ui.activities.SettingsActivity.java
private static boolean isShortCutIntent(final Intent intent) { Set<String> categories = intent.getCategories(); return (categories != null) && categories.contains("com.android.settings.SHORTCUT"); }
From source file:com.andernity.launcher2.InstallShortcutReceiver.java
private static boolean installShortcut(Context context, Intent data, ArrayList<ItemInfo> items, String name, final Intent intent, final int screen, boolean shortcutExists, final SharedPreferences sharedPrefs, int[] result) { int[] tmpCoordinates = new int[2]; if (findEmptyCell(context, items, tmpCoordinates, screen)) { if (intent != null) { if (intent.getAction() == null) { intent.setAction(Intent.ACTION_VIEW); } else if (intent.getAction().equals(Intent.ACTION_MAIN) && intent.getCategories() != null && intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); }/*from ww w . ja va 2 s .c o m*/ // By default, we allow for duplicate entries (located in // different places) boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); if (duplicate || !shortcutExists) { new Thread("setNewAppsThread") { public void run() { synchronized (sLock) { // If the new app is going to fall into the same page as before, // then just continue adding to the current page final int newAppsScreen = sharedPrefs.getInt(NEW_APPS_PAGE_KEY, screen); SharedPreferences.Editor editor = sharedPrefs.edit(); if (newAppsScreen == -1 || newAppsScreen == screen) { addToStringSet(sharedPrefs, editor, NEW_APPS_LIST_KEY, intent.toUri(0)); } editor.putInt(NEW_APPS_PAGE_KEY, screen); editor.commit(); } } }.start(); // Update the Launcher db LauncherApplication app = (LauncherApplication) context.getApplicationContext(); ShortcutInfo info = app.getModel().addShortcut(context, data, LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, tmpCoordinates[0], tmpCoordinates[1], true); if (info == null) { return false; } } else { result[0] = INSTALL_SHORTCUT_IS_DUPLICATE; } return true; } } else { result[0] = INSTALL_SHORTCUT_NO_SPACE; } return false; }
From source file:net.wequick.small.ApkBundleLauncher.java
private static String unwrapIntent(Intent intent) { Set<String> categories = intent.getCategories(); if (categories == null) return null; // Get plugin activity class name from categories Iterator<String> it = categories.iterator(); while (it.hasNext()) { String category = it.next(); if (category.charAt(0) == REDIRECT_FLAG) { return category.substring(1); }/* ww w .j a v a2s . c o m*/ } return null; }
From source file:it.jaschke.alexandria.receiver.NotificationBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent.getCategories() == null || intent.getCategories().size() != 1) { Log.e(LOG_TAG, "Expected one category."); return;// w ww. j a va 2 s . c o m } String message = null; final String category = intent.getCategories().iterator().next(); if (BookService.CATEGORY_NO_RESULT.equals(category)) { message = context.getString(R.string.msg_no_result); } else if (BookService.CATEGORY_DOWNLOAD_ERROR.equals(category)) { message = context.getString(R.string.msg_download_error); } else if (BookService.CATEGORY_RESULT_PROCESSING_ERROR.equals(category)) { message = context.getString(R.string.msg_response_processing_error); } else if (BookService.CATEGORY_ALREADY_REGISTERED.equals(category) || BookService.CATEGORY_SUCCESSFULLY_ADDED.equals(category)) { Book book = Parcels.unwrap(intent.getParcelableExtra(BookService.EXTRA_BOOK)); message = context.getString(R.string.msg_book_added, book.getId()); EventBus.getDefault().post(new BookAdditionEvent(book)); } else { Log.e(LOG_TAG, "Unexpected notification category " + category); } if (message != null) { Toast.makeText(context, message, Toast.LENGTH_LONG).show(); } }
From source file:org.linkdroid.WebhookPostService.java
public static Bundle newPostDataBundle(Intent originator) { Bundle bundle = new Bundle(); if (originator.getExtras() != null) { bundle.putAll(originator.getExtras()); }//from w w w . j a v a2 s . c om // Sanitize the linkdroid extras from data bundle in case originating // intent extras set them. We do this for all linkdroid Extras except // for the SMS extras. bundle.remove(Extras.INTENT_ACTION); bundle.remove(Extras.INTENT_TYPE); bundle.remove(Extras.INTENT_CATEGORIES); bundle.remove(Extras.HMAC); bundle.remove(Extras.NONCE); bundle.remove(Extras.STREAM); bundle.remove(Extras.STREAM_HMAC); bundle.remove(Extras.STREAM_MIME_TYPE); bundle.remove(Extras.USER_INPUT); if (originator.getAction() != null) { bundle.putString(Extras.INTENT_ACTION, originator.getAction()); } if (originator.getType() != null) { bundle.putString(Extras.INTENT_TYPE, originator.getType()); } if (originator.getCategories() != null) { bundle.putString(Extras.INTENT_CATEGORIES, StringUtils.join(originator.getCategories(), " ")); } return bundle; }