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


Java WebView.addJavascriptInterface方法代碼示例

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


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

示例1: decodePath

import android.webkit.WebView; //導入方法依賴的package包/類
public void decodePath(String srcUrl) {
    WebView webView = new WebView(Utils.getContext());

    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);//設置JS可用
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    ParseRelation relation = new ParseRelation(new IGetParamsListener() {
        @Override
        public void onGetParams(String r, String s) {
            sendRequest(srcUrl, r, s);
        }
    });

    webView.addJavascriptInterface(relation, NICK);//綁定JS和Java的聯係類,以及使用到的昵稱

    webView.loadUrl("file:///android_asset/parse.html");
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            webView.loadUrl("javascript:getParseParam('" + srcUrl + "')");
        }
    });
}
 
開發者ID:Wilshion,項目名稱:HeadlineNews,代碼行數:25,代碼來源:VideoPathDecoder.java

示例2: RecaptchaV1Task

import android.webkit.WebView; //導入方法依賴的package包/類
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
public RecaptchaV1Task(Context context, String challenge, Handler handler, RecaptchaV1.RecaptchaCallback callback) {
  this.handler = handler;
  this.callback = callback;

  webView = new WebView(context.getApplicationContext());
  webView.setWebViewClient(new RecaptchaClient());
  webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.addJavascriptInterface(this, "Android");

  webView.loadData(HTML_BODY_1 + challenge + HTML_BODY_2, HTML_MIME_TYPE, HTML_ENCODING);
}
 
開發者ID:seven332,項目名稱:android-recaptcha,代碼行數:14,代碼來源:RecaptchaV1Task.java

示例3: createRefreshableView

import android.webkit.WebView; //導入方法依賴的package包/類
@Override
protected WebView createRefreshableView(Context context, AttributeSet attrs) {
	WebView webView = super.createRefreshableView(context, attrs);

	// Need to add JS Interface so we can get the response back
	mJsCallback = new JsValueCallback();
	webView.addJavascriptInterface(mJsCallback, JS_INTERFACE_PKG);

	return webView;
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:11,代碼來源:PullToRefreshWebView2.java

示例4: setupWebView

import android.webkit.WebView; //導入方法依賴的package包/類
/**
 * Use this function to establish user connection between App and Web tracking. In that case
 * Webtrekk use everId from App to track website that is opened by WebView. Please note that website
 * should have Webtrekk integrated as well with PIXEL minimum version 4.4.0.
 * This function should be called before first main WebView page loading and in UI thread.
 *
 * @param webView - webView instance can't be null
 */
public void setupWebView(WebView webView){
    if (mContext == null){
        WebtrekkLogging.log("Can't setup WebView. Please initialize SDK first.");
        return;
    }

    if (webView == null){
        WebtrekkLogging.log("Can't setup WebView. WebView parameter is null.");
        return;
    }

    if (Looper.getMainLooper().getThread() != Thread.currentThread()){
        WebtrekkLogging.log("Can't setup WebView. Function should be called from UI thread.");
        return;
    }

    final String everId = HelperFunctions.getEverId(mContext);;

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
        webView.addJavascriptInterface(new AndroidWebViewCallback(mContext), "WebtrekkAndroidWebViewCallback");
    } else {
        webView.loadUrl("javascript: var webtrekkApplicationEverId = \"" + everId + "\";");
    }
}
 
開發者ID:Webtrekk,項目名稱:webtrekk-android-sdk,代碼行數:33,代碼來源:Webtrekk.java

示例5: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    webView = (WebView) findViewById(R.id.webView);

    WebSettings settings = webView.getSettings();
    settings.setAllowFileAccessFromFileURLs(true);
    settings.setJavaScriptEnabled(true);

    webView.addJavascriptInterface(new JavascriptHandler(this, webView), "JavascriptHandler");

    webView.loadUrl("file:///android_asset/Sample.framer/index.html");
}
 
開發者ID:mirhoseini,項目名稱:framer-android-wrapper,代碼行數:16,代碼來源:MainActivity.java

示例6: setUpWebView

import android.webkit.WebView; //導入方法依賴的package包/類
@SuppressLint("SetJavaScriptEnabled")
private void setUpWebView(WebView view) {
    view.addJavascriptInterface(mScriptBridge, "rhino");
    WebSettings webSettings = view.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowUniversalAccessFromFileURLs(true);
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:8,代碼來源:InjectableWebClient.java

示例7: SourceEditor

import android.webkit.WebView; //導入方法依賴的package包/類
/**
 * Create source editor using given web view
 *
 * @param view
 */
@SuppressLint("AddJavascriptInterface")
public SourceEditor(final WebView view) {
    WebSettings settings = view.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);
    try {
        int version = Build.VERSION.SDK_INT;
        if (version >= 11) {
            // 這個方法在API level 11 以上才可以調用,不然會發生異常
            settings.setDisplayZoomControls(false);
        }
    } catch (NumberFormatException e) {

    }
    settings.setUseWideViewPort(true);
    view.addJavascriptInterface(SourceEditor.this, "SourceEditor");
    this.view = view;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:24,代碼來源:SourceEditor.java

示例8: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@Override
public void onCreate() {
    mHandler = new Handler();
    mWebview = new WebView(this);
    mWebview.getSettings().setJavaScriptEnabled(true);
    mWebview.setWebChromeClient(new WebChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    mWebview.addJavascriptInterface(new BlocklyJavascriptInterface(),
            "BlocklyJavascriptInterface");

    mWebview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            synchronized (this) {
                mReady = true;
            }
            handleRequest();
        }
    });
    mWebview.loadUrl(BLOCKLY_COMPILER_PAGE);
}
 
開發者ID:Axe-Ishmael,項目名稱:Blockly,代碼行數:24,代碼來源:CodeGeneratorService.java

示例9: addWebImageShow

import android.webkit.WebView; //導入方法依賴的package包/類
/**
 * 添加網頁的點擊圖片展示支持
 */
@SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"})
@JavascriptInterface
public static void addWebImageShow(final Context cxt, WebView wv) {
    wv.getSettings().setJavaScriptEnabled(true);
    wv.addJavascriptInterface(new OnWebViewImageListener() {
        @Override
        @JavascriptInterface
        public void showImagePreview(String bigImageUrl) {
            if (bigImageUrl != null && !StringUtils.isEmpty(bigImageUrl)) {
                ImageGalleryActivity.show(cxt, bigImageUrl);
            }
        }
    }, "mWebViewImageListener");
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:18,代碼來源:UIHelper.java

示例10: AccountCreationWebview

import android.webkit.WebView; //導入方法依賴的package包/類
@SuppressLint("SetJavaScriptEnabled")
public AccountCreationWebview(BasePrefsWizard aParent, String url, OnAccountCreationDoneListener l){
    parent = aParent;
    creationListener = l;
    webCreationPage = url;
    
    settingsContainer = (ViewGroup) parent.findViewById(R.id.settings_container);
    validationBar = (ViewGroup) parent.findViewById(R.id.validation_bar);
    
    ViewGroup globalContainer = (ViewGroup) settingsContainer.getParent();
    
    parent.getLayoutInflater().inflate(R.layout.wizard_account_creation_webview, globalContainer);
    
    webView = (WebView) globalContainer.findViewById(R.id.webview);
    loadingProgressBar = (ProgressBar) globalContainer.findViewById(R.id.webview_progress);
    
    WebSettings webSettings = webView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(false);
    webSettings.setCacheMode(WebSettings.LOAD_NORMAL);
    webSettings.setNeedInitialFocus(true);
    webView.addJavascriptInterface(new JSInterface(), "CSipSimpleWizard");
    
    // Adds Progress bar Support
    webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            if(progress < 100) {
                loadingProgressBar.setVisibility(View.VISIBLE);
                loadingProgressBar.setProgress(progress); 
            }else {
                loadingProgressBar.setVisibility(View.GONE);
            }
        }
    });
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:38,代碼來源:AccountCreationWebview.java

示例11: exposeJsInterface

import android.webkit.WebView; //導入方法依賴的package包/類
private static void exposeJsInterface(WebView webView, CordovaBridge bridge) {
    if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)) {
        LOG.i(TAG, "Disabled addJavascriptInterface() bridge since Android version is old.");
        // Bug being that Java Strings do not get converted to JS strings automatically.
        // This isn't hard to work-around on the JS side, but it's easier to just
        // use the prompt bridge instead.
        return;
    }
    SystemExposedJsApi exposedJsApi = new SystemExposedJsApi(bridge);
    webView.addJavascriptInterface(exposedJsApi, "_cordovaNative");
}
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:12,代碼來源:SystemWebViewEngine.java

示例12: i

import android.webkit.WebView; //導入方法依賴的package包/類
@SuppressLint({"AddJavascriptInterface", "SetJavaScriptEnabled"})
private static void i(Context context) {
    WebView webView = new WebView(context);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl("file:///android_asset/mw_fingerprint.html");
    webView.addJavascriptInterface(new WebAppInterface(), "getFingerPrint");
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:8,代碼來源:DeviceInfoUtils.java

示例13: setUpWebView

import android.webkit.WebView; //導入方法依賴的package包/類
private void setUpWebView() {
    mWebView = new WebView(getContext());

    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setWebViewClient(new TwitterWebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(mUrl);
    mWebView.setLayoutParams(FILL);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");

    mContent.addView(mWebView);
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:15,代碼來源:TwitterDialog.java

示例14: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	mWebView = new WebView(this);
	mWebView.getSettings().setJavaScriptEnabled(true);
	mWebView.setWebViewClient(new WebViewClient());
	mWebView.addJavascriptInterface(this, "Android");
	mWebView.loadUrl("file:///android_asset/index.html");
	setContentView(mWebView);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:12,代碼來源:MainActivity.java

示例15: onCreate

import android.webkit.WebView; //導入方法依賴的package包/類
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_web_view);

  myWebView = (WebView) findViewById(R.id.webview);
  WebSettings webSettings = myWebView.getSettings();
  webSettings.setJavaScriptEnabled(true);
  webSettings.setDomStorageEnabled(true);
  myWebView.addJavascriptInterface(new WebAppInterface(WebViewActivity.this), "Android");
  myWebView.setWebViewClient(new MyWebViewClient());
  myWebView.loadUrl("https://arctic.000webhostapp.com/");

}
 
開發者ID:rrishabhj,項目名稱:Jugaadathon,代碼行數:14,代碼來源:WebViewActivity.java


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