List of usage examples for android.content Intent getComponent
public @Nullable ComponentName getComponent()
From source file:com.linkbubble.Settings.java
public List<ResolveInfo> getAppsThatHandleUrl(String urlAsString, PackageManager packageManager) { List<Intent> browsers = getBrowsers(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse(urlAsString)); List<ResolveInfo> infos = packageManager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); ArrayList<ResolveInfo> results = new ArrayList<ResolveInfo>(); for (ResolveInfo info : infos) { IntentFilter filter = info.filter; if (filter != null && filter.hasAction(Intent.ACTION_VIEW)) { // Check if this item is a browser, and if so, ignore it boolean packageOk = true; for (Intent browser : browsers) { if (info.activityInfo.packageName.equals(browser.getComponent().getPackageName())) { packageOk = false;// w w w . j ava2 s. c o m break; } } if (packageOk) { // Ensure TapPath is always ignored if (info.activityInfo.packageName.contains("com.digitalashes.tappath")) { //Log.d("blerg", "ignore " + info.activityInfo.packageName); packageOk = false; } else { // And some special case code for me to ignore alternate builds if (BuildConfig.DEBUG) { if (info.activityInfo.packageName.equals("com.linkbubble.playstore") || info.activityInfo.packageName.equals("com.brave.playstore")) { //Log.d("blerg", "ignore " + info.activityInfo.packageName); packageOk = false; } } else { if (info.activityInfo.packageName.equals("com.linkbubble.playstore.dev") || info.activityInfo.packageName.equals("com.brave.playstore.dev")) { //Log.d("blerg", "ignore " + info.activityInfo.packageName); packageOk = false; } } } } if (packageOk) { results.add(info); Log.d("appHandles", info.loadLabel(packageManager) + " for url:" + urlAsString); } } } if (results.size() > 0) { return results; } return null; }
From source file:com.linkbubble.Settings.java
ComponentName getDefaultBrowserComponentName(Context context) { String defaultBrowserPackageName = getDefaultBrowserPackageName(); if (defaultBrowserPackageName != null) { Intent browserIntent = context.getPackageManager().getLaunchIntentForPackage(defaultBrowserPackageName); if (browserIntent != null) { return browserIntent.getComponent(); }//from w w w. j av a 2s . c o m } return null; }
From source file:com.android.settings.HWSettings.java
/** * Checks if the component name in the intent is different from the Settings class and * returns the class name to load as a fragment. *//* w w w . ja v a 2s .co m*/ protected String getStartingFragmentClass(Intent intent) { if (mFragmentClass != null) return mFragmentClass; String intentClass = intent.getComponent().getClassName(); if (intentClass.equals(getClass().getName())) return null; if ("com.android.settings.ManageApplications".equals(intentClass) || "com.android.settings.RunningServices".equals(intentClass) || "com.android.settings.applications.StorageUse".equals(intentClass)) { // Old names of manage apps. intentClass = com.android.settings.applications.ManageApplications.class.getName(); } return intentClass; }
From source file:com.irccloud.android.activity.VideoPlayerActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_videoplayer, menu); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && getIntent() != null && getIntent().getDataString() != null) { Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse( getIntent().getDataString().replace(getResources().getString(R.string.VIDEO_SCHEME), "http"))); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, getIntent().getDataString().replace(getResources().getString(R.string.VIDEO_SCHEME), "http")); intent.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, getPackageName()); intent.putExtra(ShareCompat.EXTRA_CALLING_ACTIVITY, getPackageManager().getLaunchIntentForPackage(getPackageName()).getComponent()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK); MenuItem shareItem = menu.findItem(R.id.action_share); share = (ShareActionProviderHax) MenuItemCompat.getActionProvider(shareItem); share.onShareActionProviderSubVisibilityChangedListener = this; share.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener() { @Override//from ww w . j av a 2 s .c om public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { String name = intent.getComponent().getPackageName(); try { name = String.valueOf(getPackageManager().getActivityInfo(intent.getComponent(), 0) .loadLabel(getPackageManager())); } catch (PackageManager.NameNotFoundException e) { NetworkConnection.printStackTraceToCrashlytics(e); } Answers.getInstance().logShare(new ShareEvent().putContentType("Video").putMethod(name)); return false; } }); share.setShareIntent(intent); } else { MenuItem shareItem = menu.findItem(R.id.action_share); if (shareItem != null && shareItem.getIcon() != null) shareItem.getIcon().mutate().setColorFilter(0xFFCCCCCC, PorterDuff.Mode.SRC_ATOP); } return true; }
From source file:jackpal.androidterm.Term.java
@Override protected void onNewIntent(Intent intent) { if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { // Don't repeat action if intent comes from history return;//from w ww. j a v a 2 s.c om } String action = intent.getAction(); if (TextUtils.isEmpty(action) || !mPrivateAlias.equals(intent.getComponent())) { return; } // huge number simply opens new window // TODO: add a way to restrict max number of windows per caller (possibly via reusing BoundSession) switch (action) { case RemoteInterface.PRIVACT_OPEN_NEW_WINDOW: onResumeSelectWindow = Integer.MAX_VALUE; break; case RemoteInterface.PRIVACT_SWITCH_WINDOW: int target = intent.getIntExtra(RemoteInterface.PRIVEXTRA_TARGET_WINDOW, -1); if (target >= 0) { onResumeSelectWindow = target; } else { onResumeSelectWindowHandle = intent.getStringExtra(RemoteInterface.EXTRA_WINDOW_HANDLE); } break; } }
From source file:com.android.contacts.ContactSaveService.java
void deliverCallbackOnUiThread(final Intent callbackIntent) { // TODO: this assumes that if there are multiple instances of the same // activity registered, the last one registered is the one waiting for // the callback. Validity of this assumption needs to be verified. for (Listener listener : sListeners) { if (callbackIntent.getComponent().equals(((Activity) listener).getIntent().getComponent())) { listener.onServiceCompleted(callbackIntent); return; }//from w ww. java2 s.c om } }
From source file:org.rm3l.maoni.ui.MaoniActivity.java
private void validateAndSubmitForm() { //Validate form if (this.validateForm(mRootView)) { //TODO Check that device is actually connected to the internet prior to going any further boolean includeScreenshot = false; if (mScreenCapturingFeatureEnabled && mIncludeScreenshot != null) { includeScreenshot = mIncludeScreenshot.isChecked(); }//from ww w .j a v a2 s .c o m String contentText = ""; if (mContent != null) { contentText = mContent.getText().toString(); } final Intent intent = getIntent(); Uri screenshotUri = null; File screenshotFile = null; Uri logsUri = null; File logsFile = null; final boolean includeLogs = mLogsCapturingFeatureEnabled && mIncludeLogs != null && mIncludeLogs.isChecked(); if (includeLogs) { logsFile = new File(mWorkingDir, MAONI_LOGS_FILENAME); LogcatUtils.getLogsToFile(logsFile); } if (intent.hasExtra(FILE_PROVIDER_AUTHORITY)) { final String fileProviderAuthority = intent.getStringExtra(FILE_PROVIDER_AUTHORITY); //#11 : Potential NPE in Android's FileProvider if Provider Authority couldn't be resolved final ProviderInfo providerAuthorityInfo = this.getPackageManager() .resolveContentProvider(fileProviderAuthority, PackageManager.GET_META_DATA); if (providerAuthorityInfo == null) { Log.w(TAG, "Could not resolve file provider authority : " + fileProviderAuthority + ". Sharing of files captured not supported then. " + "See http://maoni.rm3l.org/ for setup instructions."); } else { if (mScreenshotFilePath != null) { screenshotFile = new File(mScreenshotFilePath.toString()); screenshotUri = FileProvider.getUriForFile(this, fileProviderAuthority, screenshotFile); grantUriPermission(intent.getComponent().getPackageName(), screenshotUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); } if (logsFile != null) { logsUri = FileProvider.getUriForFile(this, fileProviderAuthority, logsFile); grantUriPermission(intent.getComponent().getPackageName(), logsUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); } } } //Construct the feedback object and call the actual implementation final Feedback feedback = new Feedback(mFeedbackUniqueId, this, mAppInfo, contentText, includeScreenshot, screenshotUri, screenshotFile, includeLogs, logsUri, logsFile, mSharedPreferences); if (mListener != null) { if (mListener.onSendButtonClicked(feedback)) { finish(); } // else do *not* finish the activity } else { finish(); } } //else do nothing - this is up to the callback implementation }
From source file:com.android.leanlauncher.LauncherModel.java
/** * Make an ShortcutInfo object for a shortcut that is an application. *//*from w w w. j a v a 2 s.c o m*/ public ShortcutInfo getShortcutInfo(Intent intent, UserHandleCompat user, int titleIndex, Map<Object, CharSequence> labelCache, boolean allowMissingTarget) { if (user == null) { Log.d(TAG, "Null user found in getShortcutInfo"); return null; } ComponentName componentName = intent.getComponent(); if (componentName == null) { Log.d(TAG, "Missing component found in getShortcutInfo"); return null; } Intent newIntent = new Intent(intent.getAction(), null); newIntent.addCategory(Intent.CATEGORY_LAUNCHER); newIntent.setComponent(componentName); LauncherActivityInfoCompat lai = mLauncherApps.resolveActivity(newIntent, user); if ((lai == null) && !allowMissingTarget) { Log.d(TAG, "Missing activity found in getShortcutInfo: " + componentName); return null; } final ShortcutInfo info = new ShortcutInfo(); // From the cache. if (labelCache != null) { info.title = labelCache.get(componentName); } // from the resource if (info.title == null && lai != null) { info.title = lai.getLabel(); if (labelCache != null) { labelCache.put(componentName, info.title); } } // from the db if (info.title == null) { if (mApp.getContext() != null) { info.title = mApp.getContext().getString(titleIndex); } } // fall back to the class name of the activity if (info.title == null) { info.title = componentName.getClassName(); } info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; info.user = user; info.contentDescription = mUserManager.getBadgedLabelForUser(info.title.toString(), info.user); return info; }
From source file:com.android.gallery3d.app.PhotoPage.java
private String getErrMsgWhenStartActivityFail(ActivityChooserModel host, Intent intent) { int count = host.getActivityCount(); for (int i = 0; i < count; i++) { ResolveInfo rInfo = host.getActivity(i); if (rInfo != null && rInfo.activityInfo != null && rInfo.activityInfo.name != null && rInfo.activityInfo.name.equals(intent.getComponent().getClassName())) { String res = mActivity.getString( com.android.internal.R.string.activitychooserview_choose_application_error, rInfo.loadLabel(mActivity.getPackageManager())); Log.i(TAG, "<getErrMsgWhenStartActivityFail> return " + res); return res; }//w ww.ja v a 2s. c o m } Log.i(TAG, "<getErrMsgWhenStartActivityFail> return null"); return null; }
From source file:org.chromium.chrome.browser.tab.Tab.java
/** * Begins the tab reparenting process. Detaches the tab from its current activity and fires * an Intent to reparent the tab into its new host activity. * * @param intent An optional intent with the desired component, flags, or extras to use when * launching the new host activity. This intent's URI and action will be * overriden. This may be null if no intent customization is needed. * @param startActivityOptions Options to pass to {@link Activity#startActivity(Intent, Bundle)} * @param finalizeCallback A callback that will be called after the tab is attached to the new * host activity in {@link #attachAndFinishReparenting}. * @return Whether reparenting succeeded. If false, the tab was not removed and the intent was * not fired.//from w ww . j a v a2 s . co m */ public boolean detachAndStartReparenting(Intent intent, Bundle startActivityOptions, Runnable finalizeCallback) { ChromeActivity activity = getActivity(); if (activity == null) return false; if (intent == null) intent = new Intent(); if (intent.getComponent() == null) { intent.setClass(mThemedApplicationContext, ChromeLauncherActivity.class); } intent.setAction(Intent.ACTION_VIEW); if (TextUtils.isEmpty(intent.getDataString())) intent.setData(Uri.parse(getUrl())); if (isIncognito()) { intent.putExtra(Browser.EXTRA_APPLICATION_ID, ContextUtils.getApplicationContext().getPackageName()); intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); } IntentHandler.addTrustedIntentExtras(intent); if (ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_REPARENTING)) { TabModelSelector tabModelSelector = getTabModelSelector(); if (tabModelSelector == null) return false; mIsDetachedForReparenting = true; // Add the tab to AsyncTabParamsManager before removing it from the current model to // ensure the global count of tabs is correct. See crbug.com/611806. intent.putExtra(IntentHandler.EXTRA_TAB_ID, mId); AsyncTabParamsManager.add(mId, new TabReparentingParams(this, intent, finalizeCallback)); tabModelSelector.getModel(mIncognito).removeTab(this); // TODO(yusufo): We can't call updateWindowAndroid here and set mWindowAndroid to null // because many code paths (including navigation) expect the tab to always be associated // with an activity, and will crash. crbug.com/657007 if (mContentViewCore != null) mContentViewCore.updateWindowAndroid(null); attachTabContentManager(null); } activity.startActivity(intent, startActivityOptions); return true; }