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:Main.java

public static Intent createShortcutIntent(String url) {
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
    shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    return shortcutIntent;
}

From source file:Main.java

public static void openUrl(Context c, String url) {
    Uri uri = Uri.parse(url);//from   ww  w.j  ava 2  s .c o m
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, c.getPackageName());
    checkContextIsActivity(c, intent);
    c.startActivity(intent);
}

From source file:Main.java

protected static void launchFallbackSupportUri(Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(FALLBACK_SUPPORT_URL));
    // 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, context.getPackageName());
    intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
    intent.setPackage(context.getPackageName());
    context.startActivity(intent);//from   w  w  w  . j ava2s.  c  om
}

From source file:Main.java

/**
 * Open an URL in a message./*  w ww.j  ava2  s.  com*/
 *
 * This is intended to mirror the operation of the original
 * (see android.webkit.CallbackProxy) with one addition of intent flags
 * "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET".  This improves behavior when sublaunching
 * other apps via embedded URI's.
 *
 * We also use this hook to catch "mailto:" links and handle them locally.
 *
 * @param activity parent activity
 * @param url URL to open
 * @param senderAccountId if the URL is mailto:, we use this account as the sender.
 *        TODO When MessageCompose implements the account selector, this won't be necessary.
 *        Pass {@link Account#NO_ACCOUNT} to use the default account.
 * @return true if the URI has successfully been opened.
 */
public static boolean openUrlInMessage(Activity activity, String url, long senderAccountId) {
    // hijack mailto: uri's and handle locally
    //***
    //if (url != null && url.toLowerCase().startsWith("mailto:")) {
    //    return MessageCompose.actionCompose(activity, url, senderAccountId);
    //}

    // Handle most uri's via intent launch
    boolean result = false;
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName());
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    try {
        activity.startActivity(intent);
        result = true;
    } catch (ActivityNotFoundException ex) {
        // No applications can handle it.  Ignore.
    }
    return result;
}

From source file:co.uk.gauntface.cordova.plugin.gcmbrowserlaunch.PushNotificationReceiver.java

private void launchBrowserTask(Context context, String url, String packageName) {
    Log.v(C.TAG, "launchBrowserTask");
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    browserIntent.setPackage(packageName);
    browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    List<ResolveInfo> activitiesList = context.getPackageManager().queryIntentActivities(browserIntent, -1);
    if (activitiesList.size() > 0) {
        browserIntent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
        context.startActivity(browserIntent);
    } else {//from www.  j  a v a  2 s .  c  o m
        Intent playStoreIntent = new Intent(Intent.ACTION_VIEW);
        playStoreIntent.setData(Uri.parse("market://details?id=" + packageName));
        playStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(playStoreIntent);
        /**Intent rawIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        rawIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(rawIntent);**/
    }
}

From source file:com.android.browser.search.OpenSearchSearchEngine.java

public void startSearch(Context context, String query, Bundle appData, String extraData) {
    String uri = mSearchEngineInfo.getSearchUriForQuery(query);
    if (uri == null) {
        Log.e(TAG, "Unable to get search URI for " + mSearchEngineInfo);
    } else {//from  w  ww .ja  v a 2s  .c o m
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        // Make sure the intent goes to the Browser itself
        intent.setPackage(context.getPackageName());
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.putExtra(SearchManager.QUERY, query);
        if (appData != null) {
            intent.putExtra(SearchManager.APP_DATA, appData);
        }
        if (extraData != null) {
            intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
        context.startActivity(intent);
    }
}

From source file:com.borqs.browser.search.OpenSearchSearchEngine.java

public void startSearch(Context context, String query, Bundle appData, String extraData) {
    Log.i("OpenSearchSearchEng", "startSearch, query: " + query);
    String uri = mSearchEngineInfo.getSearchUriForQuery(query);
    if (uri == null) {
        Log.e(TAG, "Unable to get search URI for " + mSearchEngineInfo);
    } else {//  www .  j a v  a2  s . co m
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        // Make sure the intent goes to the Browser itself
        intent.setPackage(context.getPackageName());
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.putExtra(SearchManager.QUERY, query);
        if (appData != null) {
            intent.putExtra(SearchManager.APP_DATA, appData);
        }
        if (extraData != null) {
            intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
        }
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
        context.startActivity(intent);
    }
}

From source file:org.chromium.chrome.browser.ntp.ContentSuggestionsNotificationHelper.java

private static void openUrl(Uri uri) {
    Context context = ContextUtils.getApplicationContext();
    Intent intent = new Intent().setAction(Intent.ACTION_VIEW).setData(uri)
            .setClass(context, ChromeLauncherActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            .putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName())
            .putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
    IntentHandler.addTrustedIntentExtras(intent);
    context.startActivity(intent);/*from   w  ww  . j a  v  a2  s  .c  o m*/
}

From source file:com.keylesspalace.tusky.util.LinkHelper.java

/**
 * opens a link in the browser via Intent.ACTION_VIEW
 *
 * @param uri the uri to open/*from w  w w .  j  a  v  a 2  s . co  m*/
 * @param context context
 */
public static void openLinkInBrowser(Uri uri, Context context) {
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    try {
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.w("URLSpan", "Actvity was not found for intent, " + intent.toString());
    }
}

From source file:com.android.cts.browser.BrowserBenchTest.java

private void doTest(String url, ResultType typeNonFinal, ResultUnit unitNonFinal, ResultType typeFinal,
        ResultUnit unitFinal, int numberRepeat) throws InterruptedException {
    mTypeNonFinal = typeNonFinal;/*from  ww  w  . j a va  2 s . c  o m*/
    mUnitNonFinal = unitNonFinal;
    mTypeFinal = typeFinal;
    mUnitFinal = unitFinal;
    mNumberRepeat = numberRepeat;
    Uri uri = Uri.parse(url);
    for (mRunIndex = 0; mRunIndex < numberRepeat; mRunIndex++) {
        Log.i(TAG, mRunIndex + "-th round");
        mLatch = new CountDownLatch(1);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        // force using only one window or tab
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, getContext().getPackageName());
        getContext().startActivity(intent);
        boolean ok = mLatch.await(BROWSER_COMPLETION_TIMEOUT_IN_MS, TimeUnit.MILLISECONDS);
        assertTrue("timed-out", ok);
    }
    // it is somewhat awkward to handle the last one specially with Map
    int numberEntries = mResultsMap.size();
    int numberToProcess = 1;
    for (Map.Entry<String, double[]> entry : mResultsMap.entrySet()) {
        String message = entry.getKey();
        double[] scores = entry.getValue();
        if (numberToProcess == numberEntries) { // final score
            // store the whole results first
            getReportLog().printArray(message, scores, mTypeFinal, mUnitFinal);
            getReportLog().printSummary(message, Stat.getAverage(scores), mTypeFinal, mUnitFinal);
        } else { // interim results
            getReportLog().printArray(message, scores, mTypeNonFinal, mUnitNonFinal);
        }
        numberToProcess++;
    }
}