Java Code Examples for org.chromium.chrome.browser.ShortcutSource#NOTIFICATION

The following examples show how to use org.chromium.chrome.browser.ShortcutSource#NOTIFICATION . 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: WebappLauncherActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an Intent to launch the web app.
 * @param info     Information about the web app.
 * @param isWebApk If true, launch the app as a WebApkActivity.  If false, launch the app as
 *                 a WebappActivity.
 */
private Intent createWebappLaunchIntent(WebappInfo info, int source, boolean isWebApk) {
    String activityName = isWebApk ? WebApkActivity.class.getName()
            : WebappActivity.class.getName();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // Specifically assign the app to a particular WebappActivity instance.
        int namespace = isWebApk
                ? ActivityAssigner.WEBAPK_NAMESPACE : ActivityAssigner.WEBAPP_NAMESPACE;
        int activityIndex = ActivityAssigner.instance(namespace).assign(info.id());
        activityName += String.valueOf(activityIndex);
    }

    // Create an intent to launch the Webapp in an unmapped WebappActivity.
    Intent launchIntent = new Intent();
    launchIntent.setClassName(this, activityName);
    info.setWebappIntentExtras(launchIntent);

    // On L+, firing intents with the exact same data should relaunch a particular
    // Activity.
    launchIntent.setAction(Intent.ACTION_VIEW);
    launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + info.id()));

    if (!isWebApk) {
        // For WebAPK, we don't start a new task for WebApkActivity, it is just on top
        // of the WebAPK's main activity and in the same task.
        launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | ApiCompatibilityUtils.getActivityNewDocumentFlag());

        // If this is launching from a notification, we want to ensure that the URL being
        // launched is the URL in the intent. If a paused WebappActivity exists for this id,
        // then by default it will be focused and we have no way of sending the desired URL to
        // it (the intent is swallowed). As a workaround, set the CLEAR_TOP flag to ensure that
        // the existing Activity is cleared and relaunched with this intent.
        // TODO(dominickn): ideally, we want be able to route an intent to
        // WebappActivity.onNewIntent instead of restarting the Activity.
        if (source == ShortcutSource.NOTIFICATION) {
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }
    }
    return launchIntent;
}
 
Example 2
Source File: WebappLauncherActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an Intent to launch the web app.
 * @param info     Information about the web app.
 * @param isWebApk If true, launch the app as a WebApkActivity.  If false, launch the app as
 *                 a WebappActivity.
 */
private Intent createWebappLaunchIntent(WebappInfo info, int source, boolean isWebApk) {
    String activityName = isWebApk ? WebApkActivity.class.getName()
            : WebappActivity.class.getName();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // Specifically assign the app to a particular WebappActivity instance.
        int namespace = isWebApk
                ? ActivityAssigner.WEBAPK_NAMESPACE : ActivityAssigner.WEBAPP_NAMESPACE;
        int activityIndex = ActivityAssigner.instance(namespace).assign(info.id());
        activityName += String.valueOf(activityIndex);

        // Finishes the old activity if it has been assigned to a different WebappActivity. See
        // crbug.com/702998.
        for (WeakReference<Activity> activityRef : ApplicationStatus.getRunningActivities()) {
            Activity activity = activityRef.get();
            if (!(activity instanceof WebappActivity)
                    || !activity.getClass().getName().equals(activityName)) {
                continue;
            }
            WebappActivity webappActivity = (WebappActivity) activity;
            if (!TextUtils.equals(webappActivity.mWebappInfo.id(), info.id())) {
                activity.finish();
            }
            break;
        }
    }

    // Create an intent to launch the Webapp in an unmapped WebappActivity.
    Intent launchIntent = new Intent();
    launchIntent.setClassName(this, activityName);
    info.setWebappIntentExtras(launchIntent);

    // On L+, firing intents with the exact same data should relaunch a particular
    // Activity.
    launchIntent.setAction(Intent.ACTION_VIEW);
    launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + info.id()));
    launchIntent.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | ApiCompatibilityUtils.getActivityNewDocumentFlag());

    if (!isWebApk) {
        // If this is launching from a notification, we want to ensure that the URL being
        // launched is the URL in the intent. If a paused WebappActivity exists for this id,
        // then by default it will be focused and we have no way of sending the desired URL to
        // it (the intent is swallowed). As a workaround, set the CLEAR_TOP flag to ensure that
        // the existing Activity is cleared and relaunched with this intent.
        // TODO(dominickn): ideally, we want be able to route an intent to
        // WebappActivity.onNewIntent instead of restarting the Activity.
        if (source == ShortcutSource.NOTIFICATION) {
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }
    }
    return launchIntent;
}
 
Example 3
Source File: WebappInfo.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the WebappInfo was created for an Intent fired from a launcher shortcut (as
 * opposed to an intent from a push notification or other internal source).
 */
public boolean isLaunchedFromHomescreen() {
    int source = source();
    return source != ShortcutSource.NOTIFICATION && source != ShortcutSource.EXTERNAL_INTENT;
}
 
Example 4
Source File: WebappInfo.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true if the WebappInfo was created for an Intent fired from a launcher shortcut (as
 * opposed to an intent from a push notification or other internal source).
 */
public boolean isLaunchedFromHomescreen() {
    return source() != ShortcutSource.NOTIFICATION;
}
 
Example 5
Source File: WebappInfo.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true if the WebappInfo was created for an Intent fired from a launcher shortcut (as
 * opposed to an intent from a push notification or other internal source).
 */
public boolean isLaunchedFromHomescreen() {
    return source() != ShortcutSource.NOTIFICATION;
}