Example usage for android.content Intent resolveActivity

List of usage examples for android.content Intent resolveActivity

Introduction

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

Prototype

public ComponentName resolveActivity(@NonNull PackageManager pm) 

Source Link

Document

Return the Activity component that should be used to handle this intent.

Usage

From source file:bolts.MeasurementEvent.java

private static Bundle getApplinkLogData(Context context, String eventName, Bundle appLinkData,
        Intent applinkIntent) {
    Bundle logData = new Bundle();
    ComponentName resolvedActivity = applinkIntent.resolveActivity(context.getPackageManager());

    if (resolvedActivity != null) {
        logData.putString("class", resolvedActivity.getShortClassName());
    }//from   w ww  . j  a v a 2s. c  om

    if (APP_LINK_NAVIGATE_OUT_EVENT_NAME.equals(eventName)) {
        if (resolvedActivity != null) {
            logData.putString("package", resolvedActivity.getPackageName());
        }
        if (applinkIntent.getData() != null) {
            logData.putString("outputURL", applinkIntent.getData().toString());
        }
        if (applinkIntent.getScheme() != null) {
            logData.putString("outputURLScheme", applinkIntent.getScheme());
        }
    } else if (APP_LINK_NAVIGATE_IN_EVENT_NAME.equals(eventName)) {
        if (applinkIntent.getData() != null) {
            logData.putString("inputURL", applinkIntent.getData().toString());
        }
        if (applinkIntent.getScheme() != null) {
            logData.putString("inputURLScheme", applinkIntent.getScheme());
        }
    }

    for (String key : appLinkData.keySet()) {
        Object o = appLinkData.get(key);
        if (o instanceof Bundle) {
            for (String subKey : ((Bundle) o).keySet()) {
                String logValue = objectToJSONString(((Bundle) o).get(subKey));
                if (key.equals("referer_app_link")) {
                    if (subKey.equalsIgnoreCase("url")) {
                        logData.putString("refererURL", logValue);
                        continue;
                    } else if (subKey.equalsIgnoreCase("app_name")) {
                        logData.putString("refererAppName", logValue);
                        continue;
                    } else if (subKey.equalsIgnoreCase("package")) {
                        logData.putString("sourceApplication", logValue);
                        continue;
                    }
                }
                logData.putString(key + "/" + subKey, logValue);
            }
        } else {
            String logValue = objectToJSONString(o);
            if (key.equals("target_url")) {
                Uri targetURI = Uri.parse(logValue);
                logData.putString("targetURL", targetURI.toString());
                logData.putString("targetURLHost", targetURI.getHost());
                continue;
            }
            logData.putString(key, logValue);
        }
    }
    return logData;
}

From source file:com.hch.beautyenjoy.tools.IntentUtils.java

/**
 * Send message//from w  w w  . j  a v a 2  s  . com
 */
public static void sendMessage(Context context, String sendNo, String sendContent) {
    Uri uri = Uri.parse("smsto:" + sendNo);
    Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
    intent.putExtra("sms_body", sendContent);
    ComponentName componentName = intent.resolveActivity(context.getPackageManager());
    if (componentName != null) {
        context.startActivity(intent);
    }
}

From source file:com.hch.beautyenjoy.tools.IntentUtils.java

/**
 * Search a word in a browser//from  www  .j  a  va  2 s.  c om
 */
public static void search(Context context, String string) {
    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.putExtra(SearchManager.QUERY, string);
    ComponentName componentName = intent.resolveActivity(context.getPackageManager());
    if (componentName != null) {
        context.startActivity(intent);
    }
}

From source file:com.ox.utils.IntentUtils.java

/**
 * /*from w w w.j  a  v a2s. c  o m*/
 * @param context
 */
public static void market(Context context) {
    Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ComponentName componentName = intent.resolveActivity(context.getPackageManager());
    if (componentName != null) {
        context.startActivity(intent);
    }
}

From source file:com.hch.beautyenjoy.tools.IntentUtils.java

/**
 * /*from   www  . j a  va2  s  . c  om*/
 * @param context
 */
public static void market(Context context) {
    Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ComponentName componentName = intent.resolveActivity(context.getPackageManager());
    if (componentName != null) {
        context.startActivity(intent);
    } else {
        Toast.makeText(context, "", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callMayDeepLink(WebView webView, Uri uri) {
    boolean mayDeepLink;
    String cb = uri.getQueryParameter("cb");
    String urlParam = uri.getQueryParameter("url");

    if ((webView.getContext() == null) || (webView.getContext().getPackageManager() == null)
            || (urlParam == null)) {//from  ww  w.  j  a va2  s  . co m
        mayDeepLink = false;
    } else {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Uri.decode(urlParam)));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mayDeepLink = intent.resolveActivity(webView.getContext().getPackageManager()) != null;
    }

    LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
    list.add(new BasicNameValuePair(KEY_CALLER, CALL_MAYDEEPLINK));
    list.add(new BasicNameValuePair("mayDeepLink", String.valueOf(mayDeepLink)));
    loadResult(webView, cb, list);
}

From source file:de.baumann.hhsmoodle.helper.helper_webView.java

public static void webView_WebViewClient(final Activity from, final SwipeRefreshLayout swipeRefreshLayout,
        final WebView webView) {

    webView.setWebViewClient(new WebViewClient() {

        ProgressDialog progressDialog;//from  w  ww . j  av a  2s .c o  m
        int numb;

        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

            ViewPager viewPager = (ViewPager) from.findViewById(R.id.viewpager);
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
            sharedPref.edit().putString("loadURL", webView.getUrl()).apply();

            if (viewPager.getCurrentItem() == 0) {
                if (url != null) {
                    from.setTitle(webView.getTitle());
                }
            }

            if (url != null && url.contains("moodle.huebsch.ka.schule-bw.de/moodle/")
                    && url.contains("/login/")) {

                if (viewPager.getCurrentItem() == 0 && numb != 1) {
                    progressDialog = new ProgressDialog(from);
                    progressDialog.setTitle(from.getString(R.string.login_title));
                    progressDialog.setMessage(from.getString(R.string.login_text));
                    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            from.getString(R.string.toast_settings), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    helper_main.switchToActivity(from, Activity_settings.class, true);
                                }
                            });
                    progressDialog.show();
                    numb = 1;
                    progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            numb = 0;
                        }
                    });
                }

            } else if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.cancel();
                numb = 0;
            }

            swipeRefreshLayout.setRefreshing(false);

            class_SecurePreferences sharedPrefSec = new class_SecurePreferences(from, "sharedPrefSec",
                    "Ywn-YM.XK$b:/:&CsL8;=L,y4", true);
            String username = sharedPrefSec.getString("username");
            String password = sharedPrefSec.getString("password");

            final String js = "javascript:" + "document.getElementById('password').value = '" + password + "';"
                    + "document.getElementById('username').value = '" + username + "';"
                    + "var ans = document.getElementsByName('answer');"
                    + "document.getElementById('loginbtn').click()";

            if (Build.VERSION.SDK_INT >= 19) {
                view.evaluateJavascript(js, new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String s) {

                    }
                });
            } else {
                view.loadUrl(js);
            }
        }

        @SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            final Uri uri = Uri.parse(url);
            return handleUri(uri);
        }

        @TargetApi(Build.VERSION_CODES.N)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            final Uri uri = request.getUrl();
            return handleUri(uri);
        }

        private boolean handleUri(final Uri uri) {
            Log.i(TAG, "Uri =" + uri);
            final String url = uri.toString();
            // Based on some condition you need to determine if you are going to load the url
            // in your web view itself or in a browser.
            // You can use `host` or `scheme` or any part of the `uri` to decide.

            if (url.startsWith("http"))
                return false;//open web links as usual
            //try to find browse activity to handle uri
            Uri parsedUri = Uri.parse(url);
            PackageManager packageManager = from.getPackageManager();
            Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri);
            if (browseIntent.resolveActivity(packageManager) != null) {
                from.startActivity(browseIntent);
                return true;
            }
            //if not activity found, try to parse intent://
            if (url.startsWith("intent:")) {
                try {
                    Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                    if (intent.resolveActivity(from.getPackageManager()) != null) {
                        from.startActivity(intent);
                        return true;
                    }
                    //try to find fallback url
                    String fallbackUrl = intent.getStringExtra("browser_fallback_url");
                    if (fallbackUrl != null) {
                        webView.loadUrl(fallbackUrl);
                        return true;
                    }
                    //invite to install
                    Intent marketIntent = new Intent(Intent.ACTION_VIEW)
                            .setData(Uri.parse("market://details?id=" + intent.getPackage()));
                    if (marketIntent.resolveActivity(packageManager) != null) {
                        from.startActivity(marketIntent);
                        return true;
                    }
                } catch (URISyntaxException e) {
                    //not an intent uri
                }
            }
            return true;//do nothing in other cases
        }
    });
}

From source file:de.baumann.browser.helper.helper_webView.java

public static void webView_WebViewClient(final Activity from, final SwipeRefreshLayout swipeRefreshLayout,
        final WebView webView, final EditText editText) {

    webView.setWebViewClient(new WebViewClient() {

        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            swipeRefreshLayout.setRefreshing(false);
            editText.setText(webView.getTitle());
            if (webView.getTitle() != null && !webView.getTitle().equals("about:blank")) {
                try {
                    final Database_History db = new Database_History(from);
                    db.addBookmark(webView.getTitle(), webView.getUrl());
                    db.close();/*  w  w w.  ja  v  a 2  s .c o m*/
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        @SuppressWarnings("deprecation")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            final Uri uri = Uri.parse(url);
            return handleUri(uri);
        }

        @TargetApi(Build.VERSION_CODES.N)
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            final Uri uri = request.getUrl();
            return handleUri(uri);
        }

        private boolean handleUri(final Uri uri) {

            Log.i(TAG, "Uri =" + uri);
            final String url = uri.toString();
            // Based on some condition you need to determine if you are going to load the url
            // in your web view itself or in a browser.
            // You can use `host` or `scheme` or any part of the `uri` to decide.

            if (url.startsWith("http"))
                return false;//open web links as usual
            //try to find browse activity to handle uri
            Uri parsedUri = Uri.parse(url);
            PackageManager packageManager = from.getPackageManager();
            Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri);
            if (browseIntent.resolveActivity(packageManager) != null) {
                from.startActivity(browseIntent);
                return true;
            }
            //if not activity found, try to parse intent://
            if (url.startsWith("intent:")) {
                try {
                    Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                    if (intent.resolveActivity(from.getPackageManager()) != null) {
                        from.startActivity(intent);
                        return true;
                    }
                    //try to find fallback url
                    String fallbackUrl = intent.getStringExtra("browser_fallback_url");
                    if (fallbackUrl != null) {
                        webView.loadUrl(fallbackUrl);
                        return true;
                    }
                    //invite to install
                    Intent marketIntent = new Intent(Intent.ACTION_VIEW)
                            .setData(Uri.parse("market://details?id=" + intent.getPackage()));
                    if (marketIntent.resolveActivity(packageManager) != null) {
                        from.startActivity(marketIntent);
                        return true;
                    }
                } catch (URISyntaxException e) {
                    //not an intent uri
                }
            }
            return true;//do nothing in other cases
        }

    });
}

From source file:am.project.x.utils.ContextUtils.java

/**
 * ???/*from  w  w  w .j a  va  2 s.c  o  m*/
 *
 * @param context    Context
 * @param subject    
 * @param attachment 
 * @param addresses  ?
 */
public static void sendEmail(Context context, @Nullable String subject, @Nullable Uri attachment,
        String... addresses) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:"));
    intent.putExtra(Intent.EXTRA_EMAIL, addresses);
    if (subject != null)
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (attachment != null)
        intent.putExtra(Intent.EXTRA_STREAM, attachment);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);
    }
}

From source file:com.ox.utils.IntentUtils.java

/**
 * send email/*from www  .ja  v a2 s  . c o m*/
 *
 * @param email email address
 */
public static void sendEmail(Context context, String email) {
    Intent data = new Intent(Intent.ACTION_SENDTO);
    data.setData(Uri.parse("mailto:" + email));
    data.putExtra(Intent.EXTRA_SUBJECT, "[ " + AppUtils.getApplicationName(context) + " ] " + "??");
    ComponentName componentName = data.resolveActivity(context.getPackageManager());
    if (componentName != null) {
        context.startActivity(data);
    } else {
        Toast.makeText(context, "", Toast.LENGTH_SHORT).show();
    }
}