Java Code Examples for org.chromium.chrome.browser.IntentHandler#startActivityForTrustedIntent()

The following examples show how to use org.chromium.chrome.browser.IntentHandler#startActivityForTrustedIntent() . 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: 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 2
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 3
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 4
Source File: DownloadUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Opens a file in Chrome or in another app if appropriate.
 * @param file path to the file to open.
 * @param mimeType mime type of the file.
 * @param isOffTheRecord whether we are in an off the record context.
 * @return whether the file could successfully be opened.
 */
public static boolean openFile(File file, String mimeType, boolean isOffTheRecord) {
    Context context = ContextUtils.getApplicationContext();
    Intent viewIntent = createViewIntentForDownloadItem(Uri.fromFile(file), mimeType);
    DownloadManagerService service = DownloadManagerService.getDownloadManagerService(context);

    // Check if Chrome should open the file itself.
    if (service.isDownloadOpenableInBrowser(isOffTheRecord, mimeType)) {
        // Share URIs use the content:// scheme when able, which looks bad when displayed
        // in the URL bar.
        Uri fileUri = Uri.fromFile(file);
        Uri shareUri = getUriForItem(file);
        String normalizedMimeType = Intent.normalizeMimeType(mimeType);

        Intent intent =
                getMediaViewerIntentForDownloadItem(fileUri, shareUri, normalizedMimeType);
        IntentHandler.startActivityForTrustedIntent(intent, context);
        return true;
    }

    // Check if any apps can open the file.
    try {
        context.startActivity(viewIntent);
        return true;
    } catch (ActivityNotFoundException e) {
        // Can't launch the Intent.
        Toast.makeText(context, context.getString(R.string.download_cant_open_file),
                     Toast.LENGTH_SHORT)
                .show();
        return false;
    }
}
 
Example 5
Source File: DownloadUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Opens a file in Chrome or in another app if appropriate.
 * @param file path to the file to open.
 * @param mimeType mime type of the file.
 * @param downloadGuid The associated download GUID.
 * @param isOffTheRecord whether we are in an off the record context.
 * @return whether the file could successfully be opened.
 */
public static boolean openFile(
        File file, String mimeType, String downloadGuid, boolean isOffTheRecord) {
    Context context = ContextUtils.getApplicationContext();
    DownloadManagerService service = DownloadManagerService.getDownloadManagerService();

    // Check if Chrome should open the file itself.
    if (service.isDownloadOpenableInBrowser(isOffTheRecord, mimeType)) {
        // Share URIs use the content:// scheme when able, which looks bad when displayed
        // in the URL bar.
        Uri fileUri = Uri.fromFile(file);
        Uri contentUri = getUriForItem(file);
        String normalizedMimeType = Intent.normalizeMimeType(mimeType);

        Intent intent =
                getMediaViewerIntentForDownloadItem(fileUri, contentUri, normalizedMimeType);
        IntentHandler.startActivityForTrustedIntent(intent);
        service.updateLastAccessTime(downloadGuid, isOffTheRecord);
        return true;
    }

    // Check if any apps can open the file.
    try {
        // TODO(qinmin): Move this to an AsyncTask so we don't need to temper with strict mode.
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        Uri uri = ApiCompatibilityUtils.getUriForDownloadedFile(file);
        StrictMode.setThreadPolicy(oldPolicy);
        Intent viewIntent = createViewIntentForDownloadItem(uri, mimeType);
        context.startActivity(viewIntent);
        service.updateLastAccessTime(downloadGuid, isOffTheRecord);
        return true;
    } catch (ActivityNotFoundException e) {
        // Can't launch the Intent.
        Toast.makeText(context, context.getString(R.string.download_cant_open_file),
                     Toast.LENGTH_SHORT)
                .show();
        return false;
    }
}
 
Example 6
Source File: HistoryManager.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Open the provided url.
 * @param url The url to open.
 * @param isIncognito Whether to open the url in an incognito tab. If null, the tab
 *                    will open in the current tab model.
 * @param createNewTab Whether a new tab should be created. If false, the item will clobber the
 *                     the current tab.
 */
public void openUrl(String url, Boolean isIncognito, boolean createNewTab) {
    IntentHandler.startActivityForTrustedIntent(
            getOpenUrlIntent(url, isIncognito, createNewTab));
}