当前位置: 首页>>代码示例>>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;未经允许,请勿转载。