Example usage for android.content Intent setSelector

List of usage examples for android.content Intent setSelector

Introduction

In this page you can find the example usage for android.content Intent setSelector.

Prototype

public void setSelector(@Nullable Intent selector) 

Source Link

Document

Set a selector for this Intent.

Usage

From source file:org.apache.cordova.CordovaUriHelper.java

/**
 * Give the host application a chance to take over the control when a new url
 * is about to be loaded in the current WebView.
 *
 * @param view          The WebView that is initiating the callback.
 * @param url           The url to be loaded.
 * @return              true to override, false for default behavior
 *//*from ww w  .  ja v  a2 s  .  com*/
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    // The WebView should support http and https when going on the Internet
    if (url.startsWith("http:") || url.startsWith("https:")) {
        // Check if it's an exec() bridge command message.
        if (NativeToJsMessageQueue.ENABLE_LOCATION_CHANGE_EXEC_MODE
                && url.startsWith(CORDOVA_EXEC_URL_PREFIX)) {
            handleExecUrl(url);
        }
        // We only need to whitelist sites on the Internet! 
        else if (Config.isUrlWhiteListed(url)) {
            return false;
        }
    }
    // Give plugins the chance to handle the url
    else if (this.appView.pluginManager.onOverrideUrlLoading(url)) {

    } else if (url.startsWith("file://") | url.startsWith("data:")) {
        //This directory on WebKit/Blink based webviews contains SQLite databases!
        //DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
        return url.contains("app_webview");
    } else {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(url));
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.setComponent(null);
            intent.setSelector(null);
            this.cordova.getActivity().startActivity(intent);
        } catch (android.content.ActivityNotFoundException e) {
            LOG.e(TAG, "Error loading url " + url, e);
        }
    }
    //Default behaviour should be to load the default intent, let's see what happens! 
    return true;
}