android.provider.Browser Java Examples

The following examples show how to use android.provider.Browser. 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: Tab.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
 *         foreground, or null if this isn't possible.
 */
@Nullable
public static Intent createBringTabToFrontIntent(int tabId) {
    // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
    // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
    List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : list) {
        Activity activity = ref.get();
        if (activity instanceof CustomTabActivity
                && ((CustomTabActivity) activity).getActivityTab() != null
                && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
            return null;
        }
    }

    String packageName = ContextUtils.getApplicationContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName);
    intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId);
    intent.setPackage(packageName);
    return intent;
}
 
Example #2
Source File: Tab.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
 *         foreground, or null if this isn't possible.
 */
public static Intent createBringTabToFrontIntent(int tabId) {
    // Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
    // {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
    List<WeakReference<Activity>> list = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> ref : list) {
        Activity activity = ref.get();
        if (activity instanceof CustomTabActivity
                && ((CustomTabActivity) activity).getActivityTab() != null
                && tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
            return null;
        }
    }

    String packageName = ContextUtils.getApplicationContext().getPackageName();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, packageName);
    intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT.name(), tabId);
    intent.setPackage(packageName);
    return intent;
}
 
Example #3
Source File: IntentHandler.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a String (or null) containing the extra headers sent by the intent, if any.
 *
 * This methods skips the referrer header.
 *
 * @param intent The intent containing the bundle extra with the HTTP headers.
 */
public static String getExtraHeadersFromIntent(Intent intent) {
    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    StringBuilder extraHeaders = new StringBuilder();
    Iterator<String> keys = bundleExtraHeaders.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US))) continue;
        if (extraHeaders.length() != 0) extraHeaders.append("\n");
        extraHeaders.append(key);
        extraHeaders.append(": ");
        extraHeaders.append(value);
    }
    return extraHeaders.length() == 0 ? null : extraHeaders.toString();
}
 
Example #4
Source File: IntentHandler.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a String (or null) containing the extra headers sent by the intent, if any.
 *
 * This methods skips the referrer header.
 *
 * @param intent The intent containing the bundle extra with the HTTP headers.
 */
public static String getExtraHeadersFromIntent(Intent intent) {
    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    StringBuilder extraHeaders = new StringBuilder();
    Iterator<String> keys = bundleExtraHeaders.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US))) continue;
        if (extraHeaders.length() != 0) extraHeaders.append("\n");
        extraHeaders.append(key);
        extraHeaders.append(": ");
        extraHeaders.append(value);
    }
    return extraHeaders.length() == 0 ? null : extraHeaders.toString();
}
 
Example #5
Source File: BookmarkUtils.java    From delion with Apache License 2.0 6 votes vote down vote up
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent, activity);
}
 
Example #6
Source File: IntentHandler.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a String (or null) containing the extra headers sent by the intent, if any.
 *
 * This methods skips the referrer header.
 *
 * @param intent The intent containing the bundle extra with the HTTP headers.
 */
public static String getExtraHeadersFromIntent(Intent intent) {
    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    StringBuilder extraHeaders = new StringBuilder();
    Iterator<String> keys = bundleExtraHeaders.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US))) continue;
        if (extraHeaders.length() != 0) extraHeaders.append("\n");
        extraHeaders.append(key);
        extraHeaders.append(": ");
        extraHeaders.append(value);
    }
    return extraHeaders.length() == 0 ? null : extraHeaders.toString();
}
 
Example #7
Source File: UrlUtils.java    From EmojiChat with Apache License 2.0 6 votes vote down vote up
/**
 * 设置链接跳转与高亮样式
 *
 * @param url
 * @return
 */
private static ClickableSpan getClickableSpan(final String url) {
    return new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            Uri uri = Uri.parse(url);
            Context context = widget.getContext();
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
            context.startActivity(intent);
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setColor(Color.BLUE);
            ds.setUnderlineText(false);
        }
    };
}
 
Example #8
Source File: ApplicationManager.java    From product-emm with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a webclip on the device home screen.
 * @param url   - URL should be passed in as a String.
 * @param title - Title(Web app title) should be passed in as a String.
 */
public void createWebAppBookmark(String url, String title) {
	final Intent bookmarkIntent = new Intent();
	final Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
	long urlHash = url.hashCode();
	long uniqueId = (urlHash << MAX_URL_HASH) | actionIntent.hashCode();
	
	actionIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
	bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
	bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
	bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
	                        Intent.ShortcutIconResource.fromContext(context,
	                                                                R.drawable.ic_bookmark)
	);
	
	bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_action));
	context.sendBroadcast(bookmarkIntent);
}
 
Example #9
Source File: ChromeBrowserProvider.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private long addBookmark(ContentValues values) {
    String url = values.getAsString(Browser.BookmarkColumns.URL);
    String title = values.getAsString(Browser.BookmarkColumns.TITLE);
    boolean isFolder = false;
    if (values.containsKey(BOOKMARK_IS_FOLDER_PARAM)) {
        isFolder = values.getAsBoolean(BOOKMARK_IS_FOLDER_PARAM);
    }
    long parentId = INVALID_BOOKMARK_ID;
    if (values.containsKey(BOOKMARK_PARENT_ID_PARAM)) {
        parentId = values.getAsLong(BOOKMARK_PARENT_ID_PARAM);
    }
    long id = nativeAddBookmark(mNativeChromeBrowserProvider, url, title, isFolder, parentId);
    if (id == INVALID_BOOKMARK_ID) return id;

    if (isFolder) {
        updateLastModifiedBookmarkFolder(id);
    } else {
        updateLastModifiedBookmarkFolder(parentId);
    }
    return id;
}
 
Example #10
Source File: BookmarkUtils.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent);
}
 
Example #11
Source File: BookmarkUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private static void openUrl(Activity activity, String url, ComponentName componentName) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID,
            activity.getApplicationContext().getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);

    if (componentName != null) {
        intent.setComponent(componentName);
    } else {
        // If the bookmark manager is shown in a tab on a phone (rather than in a separate
        // activity) the component name may be null. Send the intent through
        // ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
        intent.setClass(activity, ChromeLauncherActivity.class);
    }

    IntentHandler.startActivityForTrustedIntent(intent, activity);
}
 
Example #12
Source File: ConnectionInfoPopup.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    if (mResetCertDecisionsButton == v) {
        nativeResetCertDecisions(mNativeConnectionInfoPopup, mWebContents);
        mDialog.dismiss();
    } else if (mCertificateViewer == v) {
        byte[][] certChain = CertificateChainHelper.getCertificateChain(mWebContents);
        if (certChain == null) {
            // The WebContents may have been destroyed/invalidated. If so,
            // ignore this request.
            return;
        }
        CertificateViewer.showCertificateChain(mContext, certChain);
    } else if (mMoreInfoLink == v) {
        mDialog.dismiss();
        try {
            Intent i = Intent.parseUri(mLinkUrl, Intent.URI_INTENT_SCHEME);
            i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
            i.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
            mContext.startActivity(i);
        } catch (Exception ex) {
            // Do nothing intentionally.
            Log.w(TAG, "Bad URI %s", mLinkUrl, ex);
        }
    }
}
 
Example #13
Source File: ContextualSearchQuickActionControl.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #14
Source File: BookmarksActivity.java    From android_coursera_1 with MIT License 6 votes vote down vote up
private void loadBookmarks() {

		Log.i(TAG, "Entered loadBookmarks()");

		String text = "";

		Cursor query = getContentResolver().query(Browser.BOOKMARKS_URI,
				projection, null, null, null);

		query.moveToFirst();
		while (query.moveToNext()) {

			text += query.getString(query
					.getColumnIndex(Browser.BookmarkColumns.TITLE));
			text += "\n";
			text += query.getString(query
					.getColumnIndex(Browser.BookmarkColumns.URL));
			text += "\n\n";

		}

		TextView box = (TextView) findViewById(R.id.text);
		box.setText(text);

		Log.i(TAG, "Bookmarks loaded");
	}
 
Example #15
Source File: IntentHandler.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the referrer, looking in the Intent extra and in the extra headers extra.
 *
 * The referrer extra takes priority over the "extra headers" one.
 *
 * @param intent The Intent containing the extras.
 * @return The referrer, or null.
 */
public static String getReferrerUrlIncludingExtraHeaders(Intent intent) {
    String referrerUrl = getReferrerUrl(intent);
    if (referrerUrl != null) return referrerUrl;

    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    for (String key : bundleExtraHeaders.keySet()) {
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US)) && isValidReferrerHeader(value)) {
            return value;
        }
    }
    return null;
}
 
Example #16
Source File: ChromeBrowserProvider.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Cursor querySearchTermFromAPI(String[] projectionIn, String selection,
        String[] selectionArgs, String sortOrder) {
    String[] projection = null;
    if (projectionIn == null || projectionIn.length == 0) {
        projection = android.provider.Browser.SEARCHES_PROJECTION;
    } else {
        projection = projectionIn;
    }
    return nativeQuerySearchTermFromAPI(mNativeChromeBrowserProvider, projection, selection,
            selectionArgs, sortOrder);
}
 
Example #17
Source File: ShareActivity.java    From reacteu-app with MIT License 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  if (resultCode == RESULT_OK) {
    switch (requestCode) {
      case PICK_BOOKMARK:
      case PICK_APP:
        showTextAsBarcode(intent.getStringExtra(Browser.BookmarkColumns.URL));
        break;
      case PICK_CONTACT:
        // Data field is content://contacts/people/984
        showContactAsBarcode(intent.getData());
        break;
    }
  }
}
 
Example #18
Source File: HistoryManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
Intent getOpenUrlIntent(String url, Boolean isIncognito, boolean createNewTab) {
    // Construct basic intent.
    Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    viewIntent.putExtra(Browser.EXTRA_APPLICATION_ID,
            mActivity.getApplicationContext().getPackageName());
    viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Determine component or class name.
    ComponentName component;
    if (DeviceFormFactor.isTablet()) {
        component = mActivity.getComponentName();
    } else {
        component = IntentUtils.safeGetParcelableExtra(
                mActivity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
    }
    if (component != null) {
        viewIntent.setComponent(component);
    } else {
        viewIntent.setClass(mActivity, ChromeLauncherActivity.class);
    }

    // Set other intent extras.
    if (isIncognito != null) {
        viewIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, isIncognito);
    }
    if (createNewTab) viewIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);

    return viewIntent;
}
 
Example #19
Source File: MultiWindowUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Sets extras on the intent used when handling "open in other window" or
 * "move to other window". Specifically, sets the class, adds the launch adjacent flag, and
 * adds extras so that Chrome behaves correctly when the back button is pressed.
 * @param intent The intent to set details on.
 * @param activity The activity firing the intent.
 * @param targetActivity The class of the activity receiving the intent.
 */
public static void setOpenInOtherWindowIntentExtras(
        Intent intent, Activity activity, Class<? extends Activity> targetActivity) {
    intent.setClass(activity, targetActivity);
    intent.addFlags(MultiWindowUtils.FLAG_ACTIVITY_LAUNCH_ADJACENT);

    // Let Chrome know that this intent is from Chrome, so that it does not close the app when
    // the user presses 'back' button.
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
}
 
Example #20
Source File: BookmarkPickerActivity.java    From reacteu-app with MIT License 5 votes vote down vote up
@Override
protected void onListItemClick(ListView l, View view, int position, long id) {
  if (!cursor.isClosed() && cursor.moveToPosition(position)) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Browser.BookmarkColumns.TITLE, cursor.getString(TITLE_COLUMN));
    intent.putExtra(Browser.BookmarkColumns.URL, cursor.getString(URL_COLUMN));
    setResult(RESULT_OK, intent);
  } else {
    setResult(RESULT_CANCELED);
  }
  finish();
}
 
Example #21
Source File: AppPickerActivity.java    From reacteu-app with MIT License 5 votes vote down vote up
@Override
protected void onListItemClick(ListView l, View view, int position, long id) {
  if (position >= 0 && position < labelsPackages.size()) {
    String url = "market://details?id=" + labelsPackages.get(position)[1];
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Browser.BookmarkColumns.URL, url);
    setResult(RESULT_OK, intent);
  } else {
    setResult(RESULT_CANCELED);
  }
  finish();
}
 
Example #22
Source File: PlaybackActivity.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_preferences:
            pickServer();
            return true;
        case R.id.menu_help_install:
            Intent intent = new Intent(Intent.ACTION_VIEW, URI_INSTALL_GUIDE);
            intent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
            startActivity(intent);
            return true;
        case R.id.menu_help_faqs:
            Intent i = new Intent(Intent.ACTION_VIEW, URI_FAQS);
            i.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
            startActivity(i);
            return true;
        case R.id.menu_action_button_first:
            Buttons.sendCommand(mMediaServer, this, Preferences.KEY_BUTTON_FIRST);
            return true;
        case R.id.menu_action_button_second:
            Buttons.sendCommand(mMediaServer, this, Preferences.KEY_BUTTON_SECOND);
            return true;
        case R.id.menu_action_button_third:
            Buttons.sendCommand(mMediaServer, this, Preferences.KEY_BUTTON_THIRD);
            return true;
        case R.id.menu_action_button_fourth:
            Buttons.sendCommand(mMediaServer, this, Preferences.KEY_BUTTON_FOURTH);
            return true;
        case R.id.menu_action_button_fifth:
            Buttons.sendCommand(mMediaServer, this, Preferences.KEY_BUTTON_FIFTH);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #23
Source File: URLSpan.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View widget) {
    Uri uri = Uri.parse(getURL());
    Context context = widget.getContext();
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    context.startActivity(intent);
}
 
Example #24
Source File: IntentHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the referrer, looking in the Intent extra and in the extra headers extra.
 *
 * The referrer extra takes priority over the "extra headers" one.
 *
 * @param intent The Intent containing the extras.
 * @param context The application context.
 * @return The referrer, or null.
 */
public static String getReferrerUrlIncludingExtraHeaders(Intent intent, Context context) {
    String referrerUrl = getReferrerUrl(intent, context);
    if (referrerUrl != null) return referrerUrl;

    Bundle bundleExtraHeaders = IntentUtils.safeGetBundleExtra(intent, Browser.EXTRA_HEADERS);
    if (bundleExtraHeaders == null) return null;
    for (String key : bundleExtraHeaders.keySet()) {
        String value = bundleExtraHeaders.getString(key);
        if ("referer".equals(key.toLowerCase(Locale.US)) && isValidReferrerHeader(value)) {
            return value;
        }
    }
    return null;
}
 
Example #25
Source File: IntentHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void recordExternalIntentSourceUMA(Intent intent) {
    ExternalAppId externalId = determineExternalIntentSource(mPackageName, intent);
    RecordHistogram.recordEnumeratedHistogram("MobileIntent.PageLoadDueToExternalApp",
            externalId.ordinal(), ExternalAppId.INDEX_BOUNDARY.ordinal());
    if (externalId == ExternalAppId.OTHER) {
        String appId = IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID);
        if (!TextUtils.isEmpty(appId)) {
            RapporServiceBridge.sampleString("Android.PageLoadDueToExternalApp", appId);
        }
    }
}
 
Example #26
Source File: IntentHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Determines what App was used to fire this Intent.
 * @param packageName Package name of this application.
 * @param intent Intent that was used to launch Chrome.
 * @return ExternalAppId representing the app.
 */
public static ExternalAppId determineExternalIntentSource(String packageName, Intent intent) {
    String appId = IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID);
    ExternalAppId externalId = ExternalAppId.OTHER;
    if (appId == null) {
        String url = getUrlFromIntent(intent);
        if (url != null && url.startsWith(TWITTER_LINK_PREFIX)) {
            externalId = ExternalAppId.TWITTER;
        } else if (url != null && url.startsWith(FACEBOOK_LINK_PREFIX)) {
            externalId = ExternalAppId.FACEBOOK;
        } else if (url != null && url.startsWith(NEWS_LINK_PREFIX)) {
            externalId = ExternalAppId.NEWS;
        }
    } else {
        if (appId.equals(PACKAGE_PLUS)) {
            externalId = ExternalAppId.PLUS;
        } else if (appId.equals(PACKAGE_GMAIL)) {
            externalId = ExternalAppId.GMAIL;
        } else if (appId.equals(PACKAGE_HANGOUTS)) {
            externalId = ExternalAppId.HANGOUTS;
        } else if (appId.equals(PACKAGE_MESSENGER)) {
            externalId = ExternalAppId.MESSENGER;
        } else if (appId.equals(PACKAGE_LINE)) {
            externalId = ExternalAppId.LINE;
        } else if (appId.equals(PACKAGE_WHATSAPP)) {
            externalId = ExternalAppId.WHATSAPP;
        } else if (appId.equals(PACKAGE_GSA)) {
            externalId = ExternalAppId.GSA;
        } else if (appId.equals(packageName)) {
            externalId = ExternalAppId.CHROME;
        }
    }
    return externalId;
}
 
Example #27
Source File: GoogleActivityController.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
* Opens the "Web & App Activity" settings that allows the user to control how Google uses Chrome
* browsing history.
* @param activity The activity to open the settings.
* @param accountName The account for which is requested.
*/
public void openWebAndAppActivitySettings(Activity activity, String accountName) {
    Intent intent = new Intent(
            Intent.ACTION_VIEW, Uri.parse(UrlConstants.GOOGLE_ACCOUNT_ACTIVITY_CONTROLS_URL));
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    intent.setPackage(activity.getPackageName());
    activity.startActivity(intent);
}
 
Example #28
Source File: InstantAppsHandler.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether the intent was fired from Chrome. This happens when the user gets a
 *         disambiguation dialog and chooses to stay in Chrome.
 */
private boolean isIntentFromChrome(Context context, Intent intent) {
    return context.getPackageName().equals(IntentUtils.safeGetStringExtra(
            intent, Browser.EXTRA_APPLICATION_ID))
            // We shouldn't leak internal intents with authentication tokens
            || IntentHandler.wasIntentSenderChrome(intent, context);
}
 
Example #29
Source File: MultiWindowUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Sets extras on the intent used when handling "open in other window" or
 * "move to other window". Specifically, sets the class, adds the launch adjacent flag, and
 * adds extras so that Chrome behaves correctly when the back button is pressed.
 * @param intent The intent to set details on.
 * @param activity The activity firing the intent.
 * @param targetActivity The class of the activity receiving the intent.
 */
public static void setOpenInOtherWindowIntentExtras(
        Intent intent, Activity activity, Class<? extends Activity> targetActivity) {
    intent.setClass(activity, targetActivity);
    intent.addFlags(MultiWindowUtils.FLAG_ACTIVITY_LAUNCH_ADJACENT);

    // Let Chrome know that this intent is from Chrome, so that it does not close the app when
    // the user presses 'back' button.
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
}
 
Example #30
Source File: LauncherShortcutActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String intentAction = getIntent().getAction();

    // Exit early if the original intent action isn't for opening a new tab.
    if (!intentAction.equals(ACTION_OPEN_NEW_TAB)
            && !intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
        finish();
        return;
    }

    Intent newIntent = new Intent();
    newIntent.setAction(Intent.ACTION_VIEW);
    newIntent.setData(Uri.parse(UrlConstants.NTP_URL));
    newIntent.setClass(this, ChromeLauncherActivity.class);
    newIntent.putExtra(IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, true);
    newIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    newIntent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
    IntentHandler.addTrustedIntentExtras(newIntent, this);

    if (intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
        newIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
    }

    // This system call is often modified by OEMs and not actionable. http://crbug.com/619646.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        startActivity(newIntent);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }

    finish();
}