List of usage examples for android.content Intent getCategories
public Set<String> getCategories()
From source file:com.farmerbb.taskbar.activity.KeyboardShortcutActivity.java
@SuppressWarnings("deprecation") @Override//from www .j a v a 2 s . co m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Perform different actions depending on how this activity was launched switch (getIntent().getAction()) { case Intent.ACTION_MAIN: Intent selector = getIntent().getSelector(); Set<String> categories = selector != null ? selector.getCategories() : getIntent().getCategories(); if (categories.contains(Intent.CATEGORY_APP_MAPS)) { SharedPreferences pref = U.getSharedPreferences(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false) && isInMultiWindowMode() && !FreeformHackHelper.getInstance().isFreeformHackActive()) { U.startFreeformHack(this, false, false); } Intent startStopIntent; if (pref.getBoolean("taskbar_active", false)) startStopIntent = new Intent("com.farmerbb.taskbar.QUIT"); else startStopIntent = new Intent("com.farmerbb.taskbar.START"); startStopIntent.setPackage(BuildConfig.APPLICATION_ID); sendBroadcast(startStopIntent); } else if (categories.contains(Intent.CATEGORY_APP_CALENDAR)) U.lockDevice(this); break; case Intent.ACTION_ASSIST: if (U.isServiceRunning(this, StartMenuService.class)) { LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_START_MENU")); } else { Intent intent = new Intent("com.google.android.googlequicksearchbox.TEXT_ASSIST"); if (intent.resolveActivity(getPackageManager()) == null) intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); if (intent.resolveActivity(getPackageManager()) != null) { SharedPreferences pref = U.getSharedPreferences(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false) && isInMultiWindowMode()) { intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); U.launchAppMaximized(getApplicationContext(), intent); } else { intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } } } break; } finish(); }
From source file:info.wncwaterfalls.app.AppInfoActivity.java
public boolean buildPendingDownloadIntent() { // Called by AppInfoSettingsFragment onResume() when Google Play Services is available, // but we need download of expansion file. try {/*from ww w . j av a 2 s .com*/ // Build the PendingIntent with which to open this activity from the notification Intent launchIntent = AppInfoActivity.this.getIntent(); Intent notificationRelaunchIntent = new Intent(AppInfoActivity.this, AppInfoActivity.this.getClass()); notificationRelaunchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationRelaunchIntent.setAction(launchIntent.getAction()); if (launchIntent.getCategories() != null) { for (String category : launchIntent.getCategories()) { notificationRelaunchIntent.addCategory(category); } } PendingIntent pendingIntent = PendingIntent.getActivity(AppInfoActivity.this, 0, notificationRelaunchIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Request to start the download int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(AppInfoActivity.this, pendingIntent, ExpansionDownloaderService.class); if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) { mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, ExpansionDownloaderService.class); // Connect the stub to our service so we get progress callbacks. if (null != mDownloaderClientStub) { mDownloaderClientStub.connect(this); } else { // Log.d(TAG, "Downloader client stub was still null!"); } // Return to tell the Fragment to build its download UI return true; } } catch (NameNotFoundException e) { e.printStackTrace(); return false; } return false; }
From source file:net.vivekiyer.GAL.CorporateAddressBook.java
@Override protected void onStart() { super.onStart(); FragmentManager fm = getSupportFragmentManager(); CorporateContactRecordFragment details = (CorporateContactRecordFragment) fm .findFragmentById(R.id.contact_fragment); if (details != null && details.isInLayout()) { CorporateAddressBookFragment contacts = (CorporateAddressBookFragment) fm .findFragmentById(R.id.main_fragment); contacts.setIsSelectable(true);/*ww w.ja v a 2 s.c o m*/ contacts.setViewBackground(false); FragmentTransaction ft = fm.beginTransaction(); ft.hide(details); ft.commit(); } final Intent intent = getIntent(); if (intent != null) { final Set<String> categories = intent.getCategories(); if ((categories != null) && categories.contains(Intent.CATEGORY_LAUNCHER)) { this.onSearchRequested(); } } }
From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java
@Override public void onAttach(Context context) { super.onAttach(context); Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "sources"); FirebaseAnalytics.getInstance(context).logEvent(FirebaseAnalytics.Event.VIEW_ITEM_LIST, bundle); mCurrentSourceLiveData = MuzeiDatabase.getInstance(context).sourceDao().getCurrentSource(); mCurrentSourceLiveData.observe(this, new Observer<com.google.android.apps.muzei.room.Source>() { @Override//from www. j av a2 s.com public void onChanged(@Nullable final com.google.android.apps.muzei.room.Source source) { updateSelectedItem(source, true); } }); Intent intent = ((Activity) context).getIntent(); if (intent != null && intent.getCategories() != null && intent.getCategories().contains(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES)) { FirebaseAnalytics.getInstance(context).logEvent("notification_preferences_open", null); NotificationSettingsDialogFragment.showSettings(this); } }
From source file:com.artemchep.horario.ui.activities.MainActivity.java
private int retrieveStartupItem() { Intent intent = getIntent(); // App shortcuts if (intent != null && intent.getCategories() != null) { Set<String> cat = intent.getCategories(); if (cat.contains(Heart.CATEGORY_EXAMS)) { return R.id.nav_exams; } else if (cat.contains(Heart.CATEGORY_NOTES)) { return R.id.nav_notes; } else if (cat.contains(Heart.CATEGORY_LESSONS)) { return R.id.nav_lessons; } else if (cat.contains(Heart.CATEGORY_NOTIFICATIONS)) { return R.id.nav_notifications; }/* w w w . j a va2s . co m*/ } int screen = mConfig.getInt(Config.KEY_UI_DEFAULT_SCREEN); if (screen == Config.SCREEN_LAST_OPENED) { screen = mConfig.getInt(Config.KEY_UI_LAST_SCREEN); } switch (screen) { case Config.SCREEN_DASHBOARD: return R.id.nav_overview; case Config.SCREEN_NOTIFICATIONS: return R.id.nav_notifications; case Config.SCREEN_LESSONS: return R.id.nav_lessons; case Config.SCREEN_SUBJECTS: return R.id.nav_subjects; case Config.SCREEN_TEACHERS: return R.id.nav_teachers; case Config.SCREEN_NOTES: return R.id.nav_notes; case Config.SCREEN_EXAMS: return R.id.nav_exams; case Config.SCREEN_SUPPORT: return R.id.nav_donate; case Config.SCREEN_SETTINGS: return R.id.nav_settings; } return R.id.nav_overview; }
From source file:com.tasomaniac.openwith.resolver.ResolverActivity.java
protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) { final ChooserHistory history = getHistory(); if ((mAlwaysUseOption || mAdapter.hasFilteredItem()) && mAdapter.mOrigResolveList != null) { // Build a reasonable intent filter, based on what matched. IntentFilter filter = new IntentFilter(); if (intent.getAction() != null) { filter.addAction(intent.getAction()); }/* w ww . jav a2s . com*/ Set<String> categories = intent.getCategories(); if (categories != null) { for (String cat : categories) { filter.addCategory(cat); } } filter.addCategory(Intent.CATEGORY_DEFAULT); int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK; Uri data = intent.getData(); if (cat == IntentFilter.MATCH_CATEGORY_TYPE) { String mimeType = intent.resolveType(this); if (mimeType != null) { try { filter.addDataType(mimeType); } catch (IntentFilter.MalformedMimeTypeException e) { Log.w("ResolverActivity", e); filter = null; } } } if (filter != null && data != null && data.getScheme() != null) { // We need the data specification if there was no type, // OR if the scheme is not one of our magical "file:" // or "content:" schemes (see IntentFilter for the reason). if (cat != IntentFilter.MATCH_CATEGORY_TYPE || (!"file".equals(data.getScheme()) && !"content".equals(data.getScheme()))) { filter.addDataScheme(data.getScheme()); // Look through the resolved filter to determine which part // of it matched the original Intent. if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator(); if (pIt != null) { String ssp = data.getSchemeSpecificPart(); while (ssp != null && pIt.hasNext()) { PatternMatcher p = pIt.next(); if (p.match(ssp)) { filter.addDataSchemeSpecificPart(p.getPath(), p.getType()); break; } } } } Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator(); if (aIt != null) { while (aIt.hasNext()) { IntentFilter.AuthorityEntry a = aIt.next(); if (a.match(data) >= 0) { int port = a.getPort(); filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null); break; } } } Iterator<PatternMatcher> pIt = ri.filter.pathsIterator(); if (pIt != null) { String path = data.getPath(); while (path != null && pIt.hasNext()) { PatternMatcher p = pIt.next(); if (p.match(path)) { filter.addDataPath(p.getPath(), p.getType()); break; } } } } } if (filter != null) { ContentValues values = new ContentValues(3); values.put(HOST, mRequestedUri.getHost()); values.put(COMPONENT, intent.getComponent().flattenToString()); if (alwaysCheck) { values.put(PREFERRED, true); } values.put(LAST_CHOSEN, true); getContentResolver().insert(CONTENT_URI, values); history.add(intent.getComponent().getPackageName()); } } if (intent != null) { startActivity(intent); } history.save(this); }
From source file:com.example.google.play.apkx.SampleDownloaderActivity.java
private void launchDownloader() { try {/*from w w w .ja v a2 s. c o m*/ Intent launchIntent = SampleDownloaderActivity.this.getIntent(); Intent intentToLaunchThisActivityFromNotification = new Intent(SampleDownloaderActivity.this, SampleDownloaderActivity.this.getClass()); intentToLaunchThisActivityFromNotification .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); intentToLaunchThisActivityFromNotification.setAction(launchIntent.getAction()); if (launchIntent.getCategories() != null) { for (String category : launchIntent.getCategories()) { intentToLaunchThisActivityFromNotification.addCategory(category); } } if (DownloaderClientMarshaller.startDownloadServiceIfRequired(this, PendingIntent.getActivity(SampleDownloaderActivity.this, 0, intentToLaunchThisActivityFromNotification, PendingIntent.FLAG_UPDATE_CURRENT), SampleDownloaderService.class) != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) { initializeDownloadUI(); return; } // otherwise we fall through to starting the movie } catch (NameNotFoundException e) { Log.e(LOG_TAG, "Cannot find own package! MAYDAY!"); e.printStackTrace(); } }
From source file:com.android.launcher3.Utilities.java
/** * Returns true if the intent is a valid launch intent for a launcher activity of an app. * This is used to identify shortcuts which are different from the ones exposed by the * applications' manifest file.//ww w. ja va 2 s.com * * @param launchIntent The intent that will be launched when the shortcut is clicked. */ public static boolean isLauncherAppTarget(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) && TextUtils.isEmpty(launchIntent.getDataString())) { // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE. Bundle extras = launchIntent.getExtras(); if (extras == null) { return true; } else { Set<String> keys = extras.keySet(); return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE); } } ; return false; }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * Filter the intent to a single activity so a chooser won't pop up. If not found, it tries to * resolve intent by falling back to default category. * @param intent intent to filter./*from w w w.ja v a 2 s . c o m*/ */ private void filterIntentWithCategory(final Intent intent) { /* Filter intent for the target package name */ filterIntent(intent); /* If the intent could not be resolved */ if (intent.getComponent() == null) { /* If there was no category */ if (intent.getCategories() == null) /* Notification cannot be done */ throw new ActivityNotFoundException(); /* Remove categories */ Collection<String> categories = new HashSet<String>(intent.getCategories()); for (String category : categories) intent.removeCategory(category); /* Try filtering again */ filterIntent(intent); /* Notification cannot be done, skip content */ if (intent.getComponent() == null) throw new ActivityNotFoundException(); } }
From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java
@Override public void updateEditedIntent(Intent editedIntent) { // Intent action if (mAvailbleActions != null) { editedIntent.setAction((String) mActionsSpinner.getSelectedItem()); } else {/*ww w .j av a2 s . c o m*/ String action = mActionText.getText().toString(); if ("".equals(action)) { action = null; } editedIntent.setAction(action); } // Categories { // Clear categories (why there's no api for this) Set<String> origCategories = editedIntent.getCategories(); if (origCategories != null) { for (String category : origCategories.toArray(new String[origCategories.size()])) { editedIntent.removeCategory(category); } } } // Fill categories if (mCategoryCheckBoxes != null) { // Fill categories from checkboxes for (CheckBox cb : mCategoryCheckBoxes) { String category = (String) cb.getTag(); if (cb.isChecked()) { editedIntent.addCategory(category); } } } else { // Fill categories from textfields for (TextView categoryTextView : mCategoryTextInputs) { editedIntent.addCategory(categoryTextView.getText().toString()); } } // Intent data (Uri) and type (MIME) String data = mDataText.getText().toString(); editedIntent.setDataAndType(data.equals("") ? null : Uri.parse(data), getDataType()); // Package name { String packageName = mPackageNameText.getText().toString(); if ("".equals(packageName)) { editedIntent.setPackage(null); } else { editedIntent.setPackage(packageName); } } // Set component for explicit intent updateIntentComponent(); }