當前位置: 首頁>>代碼示例>>Java>>正文


Java JavascriptInterface類代碼示例

本文整理匯總了Java中android.webkit.JavascriptInterface的典型用法代碼示例。如果您正苦於以下問題:Java JavascriptInterface類的具體用法?Java JavascriptInterface怎麽用?Java JavascriptInterface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JavascriptInterface類屬於android.webkit包,在下文中一共展示了JavascriptInterface類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@SuppressLint({"AddJavascriptInterface", "SetJavaScriptEnabled"})
private void init() {
    setClickable(false);
    setFocusable(false);

    setHorizontalScrollBarEnabled(false);

    WebSettings settings = getSettings();
    settings.setDefaultFontSize(14);
    settings.setSupportZoom(false);
    settings.setBuiltInZoomControls(false);
    settings.setDisplayZoomControls(false);
    settings.setJavaScriptEnabled(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        addJavascriptInterface(new OnWebViewImageListener() {
            @Override
            @JavascriptInterface
            public void showImagePreview(String bigImageUrl) {
                if (bigImageUrl != null && !StringUtils.isEmpty(bigImageUrl)) {
                    ImageGalleryActivity.show(getContext(), bigImageUrl);
                }
            }
        }, "mWebViewImageListener");
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:27,代碼來源:OWebView.java

示例2: fun_openCamera

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void fun_openCamera(String jsonString) {
    JSInBean jsInBean = JSBridgeUtil.getInstance().parseJsonArray(jsonString);
    try {
        int options = (int) (new JSONObject(jsInBean.getName()).getDouble("scale") * 100.0d);
        if (this.activityHandler != null) {
            Message message = new Message();
            message.what = 3;
            message.obj = Integer.valueOf(options);
            Bundle bundle = new Bundle();
            bundle.putString(a.c, jsInBean.getCallback());
            bundle.putString("callback_id", jsInBean.getCallback_id());
            message.setData(bundle);
            this.activityHandler.sendMessage(message);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    this.mActivity.startActivityForResult(new android.content.Intent("android.media.action.IMAGE_CAPTURE"), 10003);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:21,代碼來源:JavaScriptinterface.java

示例3: locationList

import android.webkit.JavascriptInterface; //導入依賴的package包/類
/**
 * 獲取經緯度集合
 * 
 * @param str
 */
@JavascriptInterface
public void locationList(final String str) {

	if (TextUtils.isEmpty(str)) {
		Toast.makeText(activity, "鏆傛棤鏁版嵁!", 1000).show();
		return;
	}
	// startActivity(new Intent(activity, OverlayDemo.class)
	// .putExtra("locationStr", str));

	// runOnUiThread(new Runnable() {
	// @Override
	// public void run() {
	// startActivity(new
	// Intent(activity,OverlayDemo.class).putExtra("locationStr",
	// str));
	// //Toast.makeText(htmlUIActivity, str+"", 1000).show();
	// //System.out.println("str----------"+str);
	// }
	// });
}
 
開發者ID:smartbeng,項目名稱:PaoMovie,代碼行數:27,代碼來源:WebViewFun.java

示例4: fun_getStorage

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void fun_getStorage(String jsonString) {
    LogInfo.log("ZSM webview js fun_getStorage jsonString: " + jsonString);
    JSInBean jsInBean = JSBridgeUtil.getInstance().parseJsonArray(jsonString);
    try {
        JSONArray name = new JSONArray(jsInBean.getName());
        StringBuilder builder = new StringBuilder();
        builder.append("{");
        for (int i = 0; i < name.length(); i++) {
            String key = name.getString(i);
            builder.append("\"" + key + "\":");
            builder.append(FileUtils.getApiFileCache(BaseApplication.getInstance(), key));
            if (i != name.length() - 1) {
                builder.append(",");
            }
        }
        builder.append("}");
        LogInfo.log("ZSM webview js fun_getStorage result: " + builder.toString());
        jsCallBack(jsInBean, builder.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        jsCallBack(jsInBean, RESULT_FAIL);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:25,代碼來源:JavaScriptinterface.java

示例5: uploadFile

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void uploadFile() {


    if (mActivityWeakReference.get() != null && mReference.get() != null) {
        mIFileUploadChooser = new FileUpLoadChooserImpl.Builder()
                .setActivity(mActivityWeakReference.get())
                .setJsChannelCallback(new FileUpLoadChooserImpl.JsChannelCallback() {
                    @Override
                    public void call(String value) {
                        if (mReference.get() != null)
                            mReference.get().getJsEntraceAccess().quickCallJs("uploadFileResult", value);
                    }
                }).setFileUploadMsgConfig(mReference.get().getDefaultMsgConfig().getChromeClientMsgCfg().getFileUploadMsgConfig())
                .setPermissionInterceptor(mReference.get().getPermissionInterceptor())
                .setWebView(mReference.get().getWebCreator().get())
                .build();
        mIFileUploadChooser.openFileChooser();
    }


}
 
開發者ID:Justson,項目名稱:AgentWeb,代碼行數:23,代碼來源:AgentWebJsInterfaceCompat.java

示例6: fun_setStorage

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void fun_setStorage(String jsonString) {
    LogInfo.log("ZSM webview js fun_setStorage jsonString: " + jsonString);
    JSInBean jsInBean = JSBridgeUtil.getInstance().parseJsonArray(jsonString);
    try {
        JSONArray name = new JSONArray(jsInBean.getName());
        for (int i = 0; i < name.length(); i++) {
            JSONObject object = name.getJSONObject(i);
            String key = object.getString("key");
            String value = object.getString(Constants.VALUE_ID);
            LogInfo.log("ZSM webview js fun_setStorage key: " + key + "  value == " + value);
            FileUtils.saveApiFileCache(BaseApplication.getInstance(), key, value);
        }
        jsCallBack(jsInBean, RESULT_SUCCEED);
    } catch (JSONException e) {
        e.printStackTrace();
        jsCallBack(jsInBean, RESULT_FAIL);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:20,代碼來源:JavaScriptinterface.java

示例7: fun_callLogout

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void fun_callLogout(String jsonString) {
    LogInfo.log("lxx", "jsonString: " + jsonString);
    JSInBean jsInBean = JSBridgeUtil.getInstance().parseJsonArray(jsonString);
    Map<String, Integer> map = new HashMap();
    map.put("result", Integer.valueOf(200));
    JSONObject logoutResultJson = new JSONObject(map);
    try {
        String callString = buildupJSCallString(jsInBean.getCallback(), jsInBean.getCallback_id(), logoutResultJson.toString());
        LogInfo.log("lxx", "fun_callLogout callString: " + callString);
        new Handler(Looper.getMainLooper()).post(new 3(this, callString));
        PreferencesManager.getInstance().logoutUser();
        String s = "javascript:LetvJSBridge.fireEvent('onlogout','" + logoutResultJson.toString() + "')";
        LogInfo.log("lxx", "fun_callLogout callString: " + s);
        new Handler(Looper.getMainLooper()).post(new 4(this, s));
        CookieManager.getInstance().removeAllCookie();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:21,代碼來源:JavaScriptinterface.java

示例8: core_getUserInfo

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void core_getUserInfo(String jsonString) {
    LogInfo.log("lxx", "fun_setStatus jsonString: " + jsonString);
    JSInBean jsInBean = JSBridgeUtil.getInstance().parseJsonArray(jsonString);
    try {
        Map<String, Object> map = new HashMap();
        map.put("username", PreferencesManager.getInstance().getUserName());
        map.put("nickname", PreferencesManager.getInstance().getNickName());
        map.put(NotificationCompat.CATEGORY_EMAIL, PreferencesManager.getInstance().getEmail());
        map.put("ssouid", PreferencesManager.getInstance().getSsouid());
        map.put("userlevel", Integer.valueOf(PreferencesManager.getInstance().getVipLevel()));
        if (1 == PreferencesManager.getInstance().getVipLevel()) {
            map.put("lasttime", Long.valueOf(PreferencesManager.getInstance().getVipCancelTime()));
        } else if (2 == PreferencesManager.getInstance().getVipLevel()) {
            map.put("lasttime", Long.valueOf(PreferencesManager.getInstance().getSeniorVipCancelTime()));
        }
        jsCallBack(jsInBean, new JSONObject(map).toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:22,代碼來源:JavaScriptinterface.java

示例9: show

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void show(String data) {
    LogInfo.log("ZSM Handler show == " + data);
    try {
        UserBean result = (UserBean) new OpenUserParser().doParse(data);
        PreferencesManager.getInstance().setUserName(result.username);
        PreferencesManager.getInstance().setUserId(result.uid);
        PreferencesManager.getInstance().setSso_tk(result.tv_token);
        PreferencesManager.getInstance().setRemember_pwd(true);
        PreferencesManager.getInstance().setNickName(result.nickname);
        PreferencesManager.getInstance().setUserMobile(result.mobile);
        PreferencesManager.getInstance().setPicture(result.picture);
        this.this$0.mRequestLoginTaskCallBack();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:LetvOpenIDOAuthLoginActivity.java

示例10: eval

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public String eval(final String script) {
    result = null;
    mWebView.post(new Runnable() {
        @Override
        public void run() {
            Log.v(TAG, "ScriptBridge.eval: " + script);
            result = mContext.evaluateString(mScriptable, script, "<eval-local>", 1, null);
            Log.v(TAG, "ScriptBridge.eval = " + result);
            synchronized (ScriptBridge.this) {
                ScriptBridge.this.notify();
            }
        }
    });
    synchronized (ScriptBridge.this) {
        try {
            ScriptBridge.this.wait();
        } catch (InterruptedException e) {
            throw new ScriptInterruptedException();
        }
    }
    return result.toString();
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:24,代碼來源:InjectableWebClient.java

示例11: showcontacts

import android.webkit.JavascriptInterface; //導入依賴的package包/類
/**
 * 該方法將被js調用,用於加載數據
 */
@JavascriptInterface
public void showcontacts() {
    // Thread[JavaBridge,5,main]
    Log.e(TAG, "js " + Thread.currentThread().toString());
    // 下麵的代碼建議在子線程中調用
    webView.post(new Runnable() {
        @Override
        public void run() {
            String json = "[{\"name\":\"siri\", \"phone\":\"18600012345\"}]";
            // 調用JS中的方法
            webView.loadUrl("javascript:show('" + json + "')");
        }
    });

}
 
開發者ID:wuhighway,項目名稱:DailyStudy,代碼行數:19,代碼來源:JavaAndH5Activity.java

示例12: imageClick

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
    public void imageClick(String imgUrl, String hasLink) {
//        Toast.makeText(context, "----點擊了圖片", Toast.LENGTH_SHORT).show();
        // 查看大圖
//        Intent intent = new Intent(context, ViewBigImageActivity.class);
//        context.startActivity(intent);
        Log.e("----點擊了圖片 url: ", "" + imgUrl);
    }
 
開發者ID:joelan,項目名稱:ClouldReader,代碼行數:9,代碼來源:ImageClickInterface.java

示例13: onPushpinAdded

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void onPushpinAdded() {
    Log.i(TAG, "onPushpinAdded");
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            IPushpinAddCallback callback = (IPushpinAddCallback) mHandler.getInterface(IPushpinAddCallback.class);
            if (callback != null) {
                callback.onPushpinAdded();
            }
        }
    });
}
 
開發者ID:bravecheng,項目名稱:BingMapDemo,代碼行數:14,代碼來源:JsPushpinAddInterface.java

示例14: showProduct

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void showProduct(String productId){
	if(productId!=null){
		//進行跳轉商品詳情
		showToastMsgShort("點擊的商品的ID為:" + productId);
	}else {
		showToastMsgShort("商品ID為空!");
	}
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:HTML5WebViewCustomAD.java

示例15: setProfile

import android.webkit.JavascriptInterface; //導入依賴的package包/類
@JavascriptInterface
public void setProfile(String json) {//base屬性 + img屬性  拚接去取圖片  goods是JSONobject
    if (json != null) {
        try {
            pList = new ArrayList<>();
            //解析json
            JSONObject object = new JSONObject(json);
            lri = new LiveRoomInfo();
            lri.setuId(object.getString("uid"));
            lri.setAcId(object.getString("acid"));
            lri.setNickName(object.getString("nickname"));
            lri.setOpenId(object.getString("openid"));
            lri.setEventUrl(object.getString("eventurl"));
            lri.setPushUrl(object.getString("pushurl"));
            lri.setRoomImgUrl(object.getString("roomimg"));
            lri.setMemberlevelid(String.valueOf(object.getInt("memberlevelid")));
            String goods = object.getString("goods");
            JSONArray object_goods = new JSONArray(goods);
            for (int i = 0; i < object_goods.length(); i++) {
                JSONObject object_good = object_goods.getJSONObject(i);
                products = new Products();
                products.setProducts_id(object_good.getString("id"));
                products.setProducts_name(object_good.getString("name"));
                products.setProducts_price(object_good.getString("price"));
                mBase = object.getString("base");
                String mBaseUrl = object_good.getString("img").startsWith("//") ? "http:" : object.getString("base");
                products.setProducts_icon(mBaseUrl + object_good.getString("img"));
                pList.add(products);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:JunGeges,項目名稱:AliZhiBoHao,代碼行數:35,代碼來源:WebActivity.java


注:本文中的android.webkit.JavascriptInterface類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。