Java Code Examples for org.chromium.chrome.browser.util.IntentUtils#safeStartActivity()
The following examples show how to use
org.chromium.chrome.browser.util.IntentUtils#safeStartActivity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContextualSearchQuickActionControl.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Sends the intent associated with the quick action if one is available. */ public void sendIntent() { if (mIntent == null) return; mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Set the Browser application ID to us in case the user chooses Chrome // as the app from the intent picker. Context context = getContext(); mIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); mIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); if (context instanceof ChromeTabbedActivity2) { // Set the window ID so the new tab opens in the correct window. mIntent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2); } IntentUtils.safeStartActivity(mContext, mIntent); }
Example 2
Source File: SearchActivity.java From 365browser with Apache License 2.0 | 6 votes |
@Override public void loadUrl(String url) { // Wait until native has loaded. if (!mIsActivityUsable) { mQueuedUrl = url; return; } // Don't do anything if the input was empty. This is done after the native check to prevent // resending a queued query after the user deleted it. if (TextUtils.isEmpty(url)) return; // Fix up the URL and send it to the full browser. String fixedUrl = UrlFormatter.fixupUrl(url); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(fixedUrl)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT); intent.setClass(this, ChromeLauncherActivity.class); IntentHandler.addTrustedIntentExtras(intent); IntentUtils.safeStartActivity(this, intent, ActivityOptionsCompat .makeCustomAnimation(this, android.R.anim.fade_in, android.R.anim.fade_out) .toBundle()); RecordUserAction.record("SearchWidget.SearchMade"); finish(); }
Example 3
Source File: SearchWidgetProvider.java From 365browser with Apache License 2.0 | 6 votes |
@VisibleForTesting static void startSearchActivity(Intent intent, boolean startVoiceSearch) { Log.d(TAG, "Launching SearchActivity: VOICE=" + startVoiceSearch); Context context = getDelegate().getContext(); // Abort if the user needs to go through First Run. if (FirstRunFlowSequencer.launch(context, intent, true)) return; // Launch the SearchActivity. Intent searchIntent = new Intent(); searchIntent.setClass(context, SearchActivity.class); searchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); searchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); searchIntent.putExtra(EXTRA_START_VOICE_SEARCH, startVoiceSearch); Bundle optionsBundle = ActivityOptionsCompat.makeCustomAnimation(context, R.anim.activity_open_enter, 0) .toBundle(); IntentUtils.safeStartActivity(context, searchIntent, optionsBundle); }
Example 4
Source File: ContextualSearchQuickActionControl.java From 365browser with Apache License 2.0 | 6 votes |
/** * Sends the intent associated with the quick action if one is available. * @param tab The current tab, used to load a URL if the quick action should open inside * Chrome. */ public void sendIntent(Tab tab) { if (mOpenQuickActionInChrome) { tab.loadUrl(new LoadUrlParams(mQuickActionUri)); return; } if (mIntent == null) return; // Set the Browser application ID to us in case the user chooses Chrome // as the app from the intent picker. Context context = getContext(); mIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); mIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true); mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (context instanceof ChromeTabbedActivity2) { // Set the window ID so the new tab opens in the correct window. mIntent.putExtra(IntentHandler.EXTRA_WINDOW_ID, 2); } IntentUtils.safeStartActivity(mContext, mIntent); }
Example 5
Source File: SearchGeolocationDisclosureInfoBar.java From AndroidChromium with Apache License 2.0 | 5 votes |
@CalledByNative private static void showSettingsPage(String searchUrl) { Context context = ContextUtils.getApplicationContext(); Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage( context, SingleWebsitePreferences.class.getName()); Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsForSite(searchUrl); settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs); IntentUtils.safeStartActivity(context, settingsIntent); }
Example 6
Source File: TabContextMenuItemDelegate.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onCall(String uri) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(uri)); IntentUtils.safeStartActivity(mTab.getActivity(), intent); }
Example 7
Source File: TabContextMenuItemDelegate.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onSendEmailMessage(String url) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(url)); IntentUtils.safeStartActivity(mTab.getActivity(), intent); }
Example 8
Source File: TabContextMenuItemDelegate.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onAddToContacts(String url) { Intent intent = new Intent(Intent.ACTION_INSERT); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setType(ContactsContract.Contacts.CONTENT_TYPE); if (MailTo.isMailTo(url)) { intent.putExtra( ContactsContract.Intents.Insert.EMAIL, MailTo.parse(url).getTo().split(",")[0]); } else if (UrlUtilities.isTelScheme(url)) { intent.putExtra(ContactsContract.Intents.Insert.PHONE, UrlUtilities.getTelNumber(url)); } IntentUtils.safeStartActivity(mTab.getActivity(), intent); }
Example 9
Source File: TabContextMenuItemDelegate.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void onOpenInNewChromeTabFromCCT(String linkUrl, boolean isIncognito) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClass(mTab.getApplicationContext(), ChromeLauncherActivity.class); intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false); if (isIncognito) { intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); intent.putExtra( Browser.EXTRA_APPLICATION_ID, mTab.getApplicationContext().getPackageName()); IntentHandler.addTrustedIntentExtras(intent); IntentHandler.setTabLaunchType(intent, TabLaunchType.FROM_EXTERNAL_APP); } IntentUtils.safeStartActivity(mTab.getActivity(), intent); }
Example 10
Source File: BrowserActionsContextMenuItemDelegate.java From 365browser with Apache License 2.0 | 5 votes |
/** * Called when the {@code linkUrl} should be opened in Chrome incognito tab. * @param linkUrl The url to open. */ public void onOpenInIncognitoTab(String linkUrl) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setPackage(mContext.getPackageName()); intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false); intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName()); IntentHandler.addTrustedIntentExtras(intent); IntentHandler.setTabLaunchType(intent, TabLaunchType.FROM_EXTERNAL_APP); IntentUtils.safeStartActivity(mContext, intent); }
Example 11
Source File: SearchGeolocationDisclosureInfoBar.java From 365browser with Apache License 2.0 | 5 votes |
@CalledByNative private static void showSettingsPage(String searchUrl) { Context context = ContextUtils.getApplicationContext(); Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage( context, SingleWebsitePreferences.class.getName()); Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsForSite(searchUrl); settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs); IntentUtils.safeStartActivity(context, settingsIntent); }
Example 12
Source File: TabContextMenuItemDelegate.java From 365browser with Apache License 2.0 | 4 votes |
@Override public void onSendTextMessage(String url) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("sms:" + UrlUtilities.getTelNumber(url))); IntentUtils.safeStartActivity(mTab.getActivity(), intent); }
Example 13
Source File: TabContextMenuItemDelegate.java From 365browser with Apache License 2.0 | 4 votes |
@Override public void onOpenInDefaultBrowser(String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); CustomTabsIntent.setAlwaysUseBrowserUI(intent); IntentUtils.safeStartActivity(mTab.getActivity(), intent); }
Example 14
Source File: FirstRunFlowSequencer.java From 365browser with Apache License 2.0 | 4 votes |
/** * Tries to launch the First Run Experience. If the Activity was launched with the wrong Intent * flags, we first relaunch it to make sure it runs in its own task, then trigger First Run. * * @param caller Activity instance that is checking if first run is necessary. * @param intent Intent used to launch the caller. * @param requiresBroadcast Whether or not the Intent triggers a BroadcastReceiver. * @return Whether startup must be blocked (e.g. via Activity#finish or dropping the Intent). */ public static boolean launch(Context caller, Intent intent, boolean requiresBroadcast) { // Check if the user just came back from the FRE. boolean firstRunActivityResult = IntentUtils.safeGetBooleanExtra( intent, FirstRunActivity.EXTRA_FIRST_RUN_ACTIVITY_RESULT, false); boolean firstRunComplete = IntentUtils.safeGetBooleanExtra( intent, FirstRunActivity.EXTRA_FIRST_RUN_COMPLETE, false); if (firstRunActivityResult && !firstRunComplete) { Log.d(TAG, "User failed to complete the FRE. Aborting"); return true; } // Tries to launch the Generic First Run Experience for intent from GSA. boolean showLightweightFre = IntentHandler.determineExternalIntentSource(caller.getPackageName(), intent) != ExternalAppId.GSA; // Check if the user needs to go through First Run at all. Intent freIntent = checkIfFirstRunIsNecessary(caller, intent, showLightweightFre); if (freIntent == null) return false; Log.d(TAG, "Redirecting user through FRE."); if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) { if (CommandLine.getInstance().hasSwitch( ChromeSwitches.ENABLE_LIGHTWEIGHT_FIRST_RUN_EXPERIENCE)) { boolean isGenericFreActive = false; List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities(); for (WeakReference<Activity> weakActivity : activities) { Activity activity = weakActivity.get(); if (activity == null) { continue; } else if (activity instanceof LightweightFirstRunActivity) { // A Generic or a new Lightweight First Run Experience will be launched // below, so finish the old Lightweight First Run Experience. activity.setResult(Activity.RESULT_CANCELED); activity.finish(); continue; } else if (activity instanceof FirstRunActivity) { isGenericFreActive = true; continue; } } if (isGenericFreActive) { // Launch the Generic First Run Experience if it was previously active. freIntent = createGenericFirstRunIntent( caller, TextUtils.equals(intent.getAction(), Intent.ACTION_MAIN)); } } // Add a PendingIntent so that the intent used to launch Chrome will be resent when // First Run is completed or canceled. addPendingIntent(caller, freIntent, intent, requiresBroadcast); freIntent.putExtra(FirstRunActivity.EXTRA_FINISH_ON_TOUCH_OUTSIDE, true); if (!(caller instanceof Activity)) freIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); IntentUtils.safeStartActivity(caller, freIntent); } else { // First Run requires that the Intent contains NEW_TASK so that it doesn't sit on top // of something else. Intent newIntent = new Intent(intent); newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); IntentUtils.safeStartActivity(caller, newIntent); } return true; }
Example 15
Source File: HistoryManager.java From 365browser with Apache License 2.0 | 4 votes |
/** * Opens the clear browsing data preference. */ public void openClearBrowsingDataPreference() { recordUserAction("ClearBrowsingData"); Intent intent = PreferencesLauncher.createIntentForClearBrowsingDataPage(mActivity); IntentUtils.safeStartActivity(mActivity, intent); }