Search in sources :

Example 1 with JavascriptInterface

use of android.webkit.JavascriptInterface in project Palm300Heroes by nicolite.

the class JsInject method showImages.

/**
 * 展示多张图片
 * @param images
 * @param position
 */
@JavascriptInterface
public void showImages(List<String> images, int position) {
    if (!ListUtils.isEmpty(images)) {
        Bundle bundle = new Bundle();
        bundle.putStringArrayList("images", (ArrayList<String>) images);
        bundle.putInt("curr", position);
        Intent intent = new Intent(context, ShowImageActivity.class);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) JavascriptInterface(android.webkit.JavascriptInterface)

Example 2 with JavascriptInterface

use of android.webkit.JavascriptInterface in project YhLibraryForAndroid by android-coco.

the class JsBaseInterfaceHolder method checkObject.

@Override
public boolean checkObject(Object v) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
        return true;
    if (AgentWebConfig.WEBVIEW_TYPE == AgentWebConfig.WEBVIEW_AGENTWEB_SAFE_TYPE)
        return true;
    boolean tag = false;
    Class clazz = v.getClass();
    Method[] mMethods = clazz.getMethods();
    for (Method mMethod : mMethods) {
        Annotation[] mAnnotations = mMethod.getAnnotations();
        for (Annotation mAnnotation : mAnnotations) {
            if (mAnnotation instanceof JavascriptInterface) {
                tag = true;
                break;
            }
        }
        if (tag)
            break;
    }
    return tag;
}
Also used : Method(java.lang.reflect.Method) JavascriptInterface(android.webkit.JavascriptInterface) Annotation(java.lang.annotation.Annotation)

Example 3 with JavascriptInterface

use of android.webkit.JavascriptInterface in project android-diplicity by zond.

the class MapView method load.

public void load(RetrofitActivity retrofitActivity, String url) {
    synchronized (this) {
        if (onFinished == null) {
            onFinished = new ArrayList<>();
        }
    }
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(retrofitActivity);
    final WebView webView = (WebView) findViewById(R.id.web_view);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDisplayZoomControls(prefs.getBoolean(RetrofitActivity.ZOOM_BUTTONS_PREF_KEY, false));
    webView.setBackgroundColor(Color.parseColor("#212121"));
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            synchronized (MapView.this) {
                if (onFinished != null) {
                    for (Runnable r : onFinished) {
                        r.run();
                    }
                }
                onFinished = null;
            }
        }
    });
    webView.addJavascriptInterface(new Object() {

        @JavascriptInterface
        public void provinceClicked(String province) {
            onClickedProvince.send(province);
        }
    }, "Android");
    Map<String, String> headers = new HashMap<>();
    headers.put("Authorization", "bearer " + retrofitActivity.getAuthToken());
    Log.d("Diplicity", "Loading game view " + url);
    webView.loadUrl(url, headers);
}
Also used : SharedPreferences(android.content.SharedPreferences) HashMap(java.util.HashMap) WebView(android.webkit.WebView) JavascriptInterface(android.webkit.JavascriptInterface) WebViewClient(android.webkit.WebViewClient)

Example 4 with JavascriptInterface

use of android.webkit.JavascriptInterface in project summer-android by cn-cerc.

the class JavaScriptProxy method wxPay.

/**
 * 供html调用 微信支付
 *
 * @param appId     app id
 * @param partnerId 商户号
 * @param prepayId  与支付单号
 * @param nonceStr  随机码
 * @param timeStamp 时间戳
 * @param sign      签名
 */
@JavascriptInterface
public void wxPay(String appId, String partnerId, String prepayId, String nonceStr, String timeStamp, String sign) {
    Toast.makeText(owner, "正在支付,请等待...", Toast.LENGTH_SHORT).show();
    Log.e("JavaScriptProxy", appId + " " + partnerId + " " + prepayId + " " + nonceStr + " " + timeStamp + " " + sign);
    msgApi = WXAPIFactory.createWXAPI(owner, appId);
    req = new PayReq();
    req.appId = appId;
    req.partnerId = partnerId;
    req.prepayId = prepayId;
    req.packageValue = "Sign=WXPay";
    req.nonceStr = nonceStr;
    req.timeStamp = timeStamp;
    req.sign = sign;
    msgApi.registerApp(req.appId);
    msgApi.sendReq(req);
}
Also used : PayReq(com.tencent.mm.sdk.modelpay.PayReq) JavascriptInterface(android.webkit.JavascriptInterface)

Example 5 with JavascriptInterface

use of android.webkit.JavascriptInterface in project incubator-weex by apache.

the class WXWebView method initWebView.

private void initWebView(WebView wv) {
    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setAppCacheEnabled(true);
    settings.setUseWideViewPort(true);
    settings.setDomStorageEnabled(true);
    settings.setSupportZoom(false);
    settings.setBuiltInZoomControls(false);
    wv.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            WXLogUtils.v("tag", "onPageOverride " + url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            WXLogUtils.v("tag", "onPageStarted " + url);
            if (mOnPageListener != null) {
                mOnPageListener.onPageStart(url);
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            WXLogUtils.v("tag", "onPageFinished " + url);
            if (mOnPageListener != null) {
                mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
            }
            if (mOnMessageListener != null) {
                evaluateJS("javascript:(window.postMessage = function(message, targetOrigin) {" + "if (message == null || !targetOrigin) return;" + (DOWNGRADE_JS_INTERFACE ? "prompt('" + BRIDGE_NAME + "://postMessage?message=' + JSON.stringify(message) + '&targetOrigin=' + targetOrigin)" : BRIDGE_NAME + ".postMessage(JSON.stringify(message), targetOrigin);") + "})");
            }
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            if (mOnErrorListener != null) {
                // mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
                mOnErrorListener.onError("error", "page error");
            }
        }

        @Override
        public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
            super.onReceivedHttpError(view, request, errorResponse);
            if (mOnErrorListener != null) {
                mOnErrorListener.onError("error", "http error");
            }
        }

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            super.onReceivedSslError(view, handler, error);
            if (mOnErrorListener != null) {
                mOnErrorListener.onError("error", "ssl error");
            }
        }
    });
    wv.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            showWebView(newProgress == 100);
            showProgressBar(newProgress != 100);
            WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            if (mOnPageListener != null) {
                mOnPageListener.onReceivedTitle(view.getTitle());
            }
        }

        @Override
        public boolean onJsPrompt(WebView view, String url, String text, String defaultValue, JsPromptResult result) {
            Uri uri = Uri.parse(text);
            String scheme = uri.getScheme();
            if (TextUtils.equals(scheme, BRIDGE_NAME)) {
                if (TextUtils.equals(uri.getAuthority(), "postMessage")) {
                    String message = uri.getQueryParameter("message");
                    String targetOrigin = uri.getQueryParameter("targetOrigin");
                    onMessage(message, targetOrigin);
                    result.confirm("success");
                } else {
                    result.confirm("fail");
                }
                return true;
            }
            return super.onJsPrompt(view, url, text, defaultValue, result);
        }
    });
    if (!DOWNGRADE_JS_INTERFACE) {
        wv.addJavascriptInterface(new Object() {

            @JavascriptInterface
            public void postMessage(String message, String targetOrigin) {
                onMessage(message, targetOrigin);
            }
        }, BRIDGE_NAME);
    }
}
Also used : SslErrorHandler(android.webkit.SslErrorHandler) WebResourceRequest(android.webkit.WebResourceRequest) SslError(android.net.http.SslError) JavascriptInterface(android.webkit.JavascriptInterface) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) WebResourceResponse(android.webkit.WebResourceResponse) WebSettings(android.webkit.WebSettings) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) JSONObject(com.alibaba.fastjson.JSONObject) WebView(android.webkit.WebView) JsPromptResult(android.webkit.JsPromptResult) WebViewClient(android.webkit.WebViewClient)

Aggregations

JavascriptInterface (android.webkit.JavascriptInterface)32 JSONObject (org.json.JSONObject)9 JSONException (org.json.JSONException)7 Intent (android.content.Intent)4 WebView (android.webkit.WebView)4 WebViewClient (android.webkit.WebViewClient)4 IOException (java.io.IOException)4 Annotation (java.lang.annotation.Annotation)4 Method (java.lang.reflect.Method)4 File (java.io.File)3 SharedPreferences (android.content.SharedPreferences)2 IBaseForumPost (forpdateam.ru.forpda.api.IBaseForumPost)2 HashMap (java.util.HashMap)2 SuppressLint (android.annotation.SuppressLint)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 SslError (android.net.http.SslError)1 Bundle (android.os.Bundle)1 AlertDialog (android.support.v7.app.AlertDialog)1 JsPromptResult (android.webkit.JsPromptResult)1