프로그래밍/Android

[안드로이드] 웹뷰 + 카카오톡 적용

소행성왕자 2022. 2. 4. 13:54
@Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                /*
                if (startUrl != null && startUrl.equals(url)) {
                    view.loadUrl(url);
                } else {
                    //交给系统处理
                    return super.shouldOverrideUrlLoading(view, url);
                }

                return true;

                 */

                // 2020.02.04 수정 : 앱에서 카카오톡 적용

                if (url.startsWith("intent:")) {
                    try {
                        Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
                        Intent existPackage = getPackageManager().getLaunchIntentForPackage(intent.getPackage());
                        if (existPackage != null) {
                            startActivity(intent);
                        } else {
                            Intent marketIntent = new Intent(Intent.ACTION_VIEW);
                            marketIntent.setData(Uri.parse("market://details?id=" + intent.getPackage()));
                            startActivity(marketIntent);
                        }
                        return true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } if (startUrl != null && startUrl.equals(url)) {
                    view.loadUrl(url);
                }
                else {
                    //交给系统处理
                    return super.shouldOverrideUrlLoading(view, url);
                }

                return true;


            }