Example usage for android.provider Browser EXTRA_APPLICATION_ID

List of usage examples for android.provider Browser EXTRA_APPLICATION_ID

Introduction

In this page you can find the example usage for android.provider Browser EXTRA_APPLICATION_ID.

Prototype

String EXTRA_APPLICATION_ID

To view the source code for android.provider Browser EXTRA_APPLICATION_ID.

Click Source Link

Document

The name of the extra data when starting the Browser from another application.

Usage

From source file:com.andrewshu.android.reddit.common.Common.java

/**
 * /*from ww w.ja  va  2s  .c  o m*/
 * @param url
 * @param context
 * @param requireNewTask set this to true if context is not an Activity
 * @param bypassParser
 * @param useExternalBrowser
 */
public static void launchBrowser(Context context, String url, String threadUrl, boolean requireNewTask,
        boolean bypassParser, boolean useExternalBrowser, boolean saveHistory) {

    try {
        if (saveHistory) {
            Browser.updateVisitedHistory(context.getContentResolver(), url, true);
        }
    } catch (Exception ex) {
        if (Constants.LOGGING)
            Log.i(TAG, "Browser.updateVisitedHistory error", ex);
    }

    Uri uri = Uri.parse(url);

    if (!bypassParser) {
        if (Util.isRedditUri(uri)) {
            String path = uri.getPath();
            Matcher matcher = COMMENT_LINK.matcher(path);
            if (matcher.matches()) {
                if (matcher.group(3) != null || matcher.group(2) != null) {
                    CacheInfo.invalidateCachedThread(context);
                    Intent intent = new Intent(context, CommentsListActivity.class);
                    intent.setData(uri);
                    intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT);
                    if (requireNewTask)
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent);
                    return;
                }
            }
            matcher = REDDIT_LINK.matcher(path);
            if (matcher.matches()) {
                CacheInfo.invalidateCachedSubreddit(context);
                Intent intent = new Intent(context, ThreadsListActivity.class);
                intent.setData(uri);
                if (requireNewTask)
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                return;
            }
            matcher = USER_LINK.matcher(path);
            if (matcher.matches()) {
                Intent intent = new Intent(context, ProfileActivity.class);
                intent.setData(uri);
                if (requireNewTask)
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                return;
            }
        } else if (Util.isRedditShortenedUri(uri)) {
            String path = uri.getPath();
            if (path.equals("") || path.equals("/")) {
                CacheInfo.invalidateCachedSubreddit(context);
                Intent intent = new Intent(context, ThreadsListActivity.class);
                intent.setData(uri);
                if (requireNewTask)
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            } else {
                // Assume it points to a thread aka CommentsList
                CacheInfo.invalidateCachedThread(context);
                Intent intent = new Intent(context, CommentsListActivity.class);
                intent.setData(uri);
                intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT);
                if (requireNewTask)
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
            return;
        }
    }
    uri = Util.optimizeMobileUri(uri);

    // Some URLs should always be opened externally, if BrowserActivity doesn't support their content.
    if (Util.isYoutubeUri(uri) || Util.isAndroidMarketUri(uri))
        useExternalBrowser = true;

    if (useExternalBrowser) {
        Intent browser = new Intent(Intent.ACTION_VIEW, uri);
        browser.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
        if (requireNewTask)
            browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(browser);
    } else {
        Intent browser = new Intent(context, BrowserActivity.class);
        browser.setData(uri);
        if (threadUrl != null)
            browser.putExtra(Constants.EXTRA_THREAD_URL, threadUrl);
        if (requireNewTask)
            browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(browser);
    }
}

From source file:in.shick.diode.common.Common.java

/**
 *
 * @param settings The {@link RedditSettings} object used to for preference-retrieving.
 * @param context The {@link Context} object to use, as necessary.
 * @param url The URL to launch in the browser.
 * @param threadUrl The (optional) URL of the comments thread for the 'View comments' menu option in the browser.
 * @param requireNewTask set this to true if context is not an Activity
 * @param bypassParser Should URI parsing be bypassed, usually true in the case an external browser is being launched.
 * @param useExternalBrowser Should the external browser app be launched instead of the internal one.
 * @param saveHistory Should the URL be entered into the browser history?
 *///from   ww  w  .  j  av  a  2  s. c o m
public static void launchBrowser(RedditSettings settings, Context context, String url, String threadUrl,
        boolean requireNewTask, boolean bypassParser, boolean useExternalBrowser, boolean saveHistory) {

    try {
        if (saveHistory) {
            Browser.updateVisitedHistory(context.getContentResolver(), url, true);
        }
    } catch (Exception ex) {
        if (Constants.LOGGING)
            Log.i(TAG, "Browser.updateVisitedHistory error", ex);
    }
    boolean forceDesktopUserAgent = false;
    if (!bypassParser && settings != null && settings.isLoadImgurImagesDirectly()) {
        Matcher m = m_imgurRegex.matcher(url);
        if (m.matches() && m.group(1) != null) {
            // We've determined it's an imgur link, no need to parse it further.
            bypassParser = true;
            url = "http://i.imgur.com/" + m.group(1);
            if (!StringUtils.isEmpty(m.group(2))) {
                String extension = m.group(2);
                if (".gifv".equalsIgnoreCase(extension)) {
                    extension = ".mp4";
                }
                url += extension;
            } else {
                // Need to give images an extension, or imgur will redirect to the mobile site.
                url += ".png";
            }
            forceDesktopUserAgent = true;
        }
    }
    if (settings != null && settings.isLoadVredditLinksDirectly()) {
        if (url.contains("v.redd.it")) {
            url += "/DASH_600_K";
        }
    }

    Uri uri = Uri.parse(url);

    if (!bypassParser) {
        if (Util.isRedditUri(uri)) {
            String path = uri.getPath();
            Matcher matcher = COMMENT_LINK.matcher(path);
            if (matcher.matches()) {
                if (matcher.group(3) != null || matcher.group(2) != null) {
                    CacheInfo.invalidateCachedThread(context);
                    Intent intent = new Intent(context, CommentsListActivity.class);
                    intent.setData(uri);
                    intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT);
                    if (requireNewTask)
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent);
                    return;
                }
            }
            matcher = REDDIT_LINK.matcher(path);
            if (matcher.matches()) {
                CacheInfo.invalidateCachedSubreddit(context);
                Intent intent = new Intent(context, ThreadsListActivity.class);
                intent.setData(uri);
                if (requireNewTask)
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                return;
            }
            matcher = USER_LINK.matcher(path);
            if (matcher.matches()) {
                Intent intent = new Intent(context, ProfileActivity.class);
                intent.setData(uri);
                if (requireNewTask)
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                return;
            }
        } else if (Util.isRedditShortenedUri(uri)) {
            String path = uri.getPath();
            if (path.equals("") || path.equals("/")) {
                CacheInfo.invalidateCachedSubreddit(context);
                Intent intent = new Intent(context, ThreadsListActivity.class);
                intent.setData(uri);
                if (requireNewTask)
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            } else {
                // Assume it points to a thread aka CommentsList
                CacheInfo.invalidateCachedThread(context);
                Intent intent = new Intent(context, CommentsListActivity.class);
                intent.setData(uri);
                intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT);
                if (requireNewTask)
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
            return;
        }
    }
    uri = Util.optimizeMobileUri(uri);

    // Some URLs should always be opened externally, if BrowserActivity doesn't support their content.
    if (Util.isYoutubeUri(uri) || Util.isAndroidMarketUri(uri)) {
        useExternalBrowser = true;
    }

    if (useExternalBrowser) {
        Intent browser = new Intent(Intent.ACTION_VIEW, uri);
        browser.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
        if (requireNewTask) {
            browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(browser);
    } else {
        Intent browser = new Intent(context, BrowserActivity.class);
        browser.setData(uri);
        if (forceDesktopUserAgent) {
            browser.putExtra(Constants.EXTRA_FORCE_UA_STRING, "desktop");
        }
        if (threadUrl != null) {
            browser.putExtra(Constants.EXTRA_THREAD_URL, threadUrl);
        }
        if (requireNewTask) {
            browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(browser);
    }
}

From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java

@Override
public void startActivity(Intent intent) {
    if (intent.getStringExtra(Browser.EXTRA_APPLICATION_ID) != null) {
        intent.removeExtra(Browser.EXTRA_APPLICATION_ID);
    }/*w  w w.  j a v  a2s.co m*/

    try {
        super.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.w(TAG, e);
        Toast.makeText(this,
                R.string.ConversationActivity_there_is_no_app_available_to_handle_this_link_on_your_device,
                Toast.LENGTH_LONG).show();
    }
}

From source file:org.wso2.iot.agent.api.ApplicationManager.java

/**
 * 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.
 *///  ww w  .  j a  va  2 s.  c  o m
public void manageWebAppBookmark(String url, String title, String operationType) throws AndroidAgentException {
    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));
    if (operationType != null) {
        if (resources.getString(R.string.operation_install).equalsIgnoreCase(operationType)) {
            bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
        } else if (resources.getString(R.string.operation_uninstall).equalsIgnoreCase(operationType)) {
            bookmarkIntent
                    .setAction(resources.getString(R.string.application_package_launcher_uninstall_action));
        } else {
            throw new AndroidAgentException("Cannot create webclip due to invalid operation type.");
        }
    } else {
        bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
    }
    context.sendBroadcastAsUser(bookmarkIntent, android.os.Process.myUserHandle());
}

From source file:im.vector.fragments.VectorMessageListFragment.java

@Override
public void onURLClick(Uri uri) {
    if (null != uri) {
        if (null != VectorUniversalLinkReceiver.parseUniversalLink(uri)) {
            // pop to the home activity
            Intent intent = new Intent(getActivity(), VectorHomeActivity.class);
            intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.putExtra(VectorHomeActivity.EXTRA_JUMP_TO_UNIVERSAL_LINK, uri);
            getActivity().startActivity(intent);
        } else {//w  ww  .j  av  a  2 s. co m
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.putExtra(Browser.EXTRA_APPLICATION_ID, getActivity().getPackageName());
            getActivity().startActivity(intent);
        }
    }
}

From source file:im.neon.fragments.VectorMessageListFragment.java

@Override
public void onURLClick(Uri uri) {
    try {//from w  w w .  j  a va 2 s .com
        if (null != uri) {
            HashMap<String, String> universalParams = VectorUniversalLinkReceiver.parseUniversalLink(uri);

            if (null != universalParams) {
                // open the member sheet from the current activity
                if (universalParams.containsKey(VectorUniversalLinkReceiver.ULINK_MATRIX_USER_ID_KEY)) {
                    Intent roomDetailsIntent = new Intent(getActivity(), VectorMemberDetailsActivity.class);
                    roomDetailsIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MEMBER_ID,
                            universalParams.get(VectorUniversalLinkReceiver.ULINK_MATRIX_USER_ID_KEY));
                    roomDetailsIntent.putExtra(VectorMemberDetailsActivity.EXTRA_MATRIX_ID,
                            mSession.getCredentials().userId);
                    getActivity().startActivityForResult(roomDetailsIntent,
                            VectorRoomActivity.GET_MENTION_REQUEST_CODE);
                } else {
                    // pop to the home activity
                    Intent intent = new Intent(getActivity(), VectorHomeActivity.class);
                    intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP
                            | android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    intent.putExtra(VectorHomeActivity.EXTRA_JUMP_TO_UNIVERSAL_LINK, uri);
                    getActivity().startActivity(intent);
                }
            } else {
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.putExtra(Browser.EXTRA_APPLICATION_ID, getActivity().getPackageName());
                getActivity().startActivity(intent);
            }
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "## onURLClick() failed " + e.getMessage());
    }
}

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 .  ja  v a 2s. c om*/
 */
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;
}

From source file:org.matrix.androidsdk.fragments.MatrixMessageListFragment.java

@Override
public void onURLClick(Uri uri) {
    if (null != uri) {
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, getActivity().getPackageName());
        getActivity().startActivity(intent);
    }/*from w  w  w  .j  a v a  2  s  . c  o  m*/
}

From source file:org.chromium.chrome.browser.tab.Tab.java

/**
 * @return Intent that tells Chrome to bring an Activity for a particular Tab back to the
 *         foreground, or null if this isn't possible.
 *///from   ww  w .  ja  va2 s .co  m
@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;
}