zoukankan      html  css  js  c++  java
  • andriod webview和h5

    1.WebBrowserActivity extends BaseActivity

    2.setContentView(R.layout.activity_web_html);

    <WebView
    android:id="@+id/wv_web_browser"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
    

    3.wv_web_browser = (WebView)findViewById(R.id.wv_web_browser);

    WebSettings webSet = wv_web_browser.getSettings();
    webSet.setJavaScriptEnabled(true);
    webSet.setJavaScriptCanOpenWindowsAutomatically(true);
    webSet.setLoadsImagesAutomatically(true);
    webSet.setSupportZoom(true);
    webSet.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
    webSet.setUseWideViewPort(true);
    webSet.setLoadWithOverviewMode(true);
    webSet.setMixedContentMode(0);
    // 设置出现缩放工具
    webSet.setBuiltInZoomControls(true);
    int sysVersion = VERSION.SDK_INT;
    if (sysVersion >= 11) {
    	webSet.setDisplayZoomControls(false);
    } else {
    	ZoomButtonsController zbc = new ZoomButtonsController(wv_web_browser);
    	zbc.getZoomControls().setVisibility(View.GONE);
    		}
    		// 设置可以访问文件
    webSet.setAllowFileAccess(true);
    webSet.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webSet.setAppCacheEnabled(true);
    webSet.setDomStorageEnabled(true);
    webSet.setDatabaseEnabled(true);
    

      

    //通知h5应用状态 通知刷新html
    informHtmlReceiver = new InformHtmlReceiver();
    IntentFilter informHtmlFilter = new IntentFilter(AppConstants.ACTION_APP_PACKAGENAME_INFORM_HTML);
    LocalBroadcastManager.getInstance(WebBrowserActivity.this).registerReceiver(informHtmlReceiver, informHtmlFilter);
    // 增加h5与本地交互方法 wv_web_browser.addJavascriptInterface(new HtmlJavascriptInterface(),"jsObj"); wv_web_browser.addJavascriptInterface(new HtmlJavaAlarmInterface(), "mstore");

      

    WebChromeClient wvcc = new WebChromeClient() {
     @Override
    public void onReceivedTitle(WebView view, String title) {
      super.onReceivedTitle(view, title);   if (!TextUtils.isEmpty(title)) { tv_classify_title.setText(title); } } }; wv_web_browser.setWebChromeClient(wvcc);

      

    /**
    	 * 调用js更新H5,js方法
    	 */
    	private class InformHtmlReceiver extends BroadcastReceiver{
    
    		@Override
    		public void onReceive(Context context, Intent intent) {
    			  final String packageName = intent.getStringExtra("packagename");
    			  String state = intent.getStringExtra("state");
    			  wv_web_browser.loadUrl("javascript:callDownState('" + packageName +"','"+state+ "')");
    		}
    	}
    

      

    public class HtmlJavaAlarmInterface {
            /**
             * 点击添加
             * 
             * @param apps_json
             */
            @JavascriptInterface
            public void setAlarm(final String endTime, final String title, final String content) {
    
                if (CalendarUtil.tranceLong(endTime) != 0) {
                    CalendarUtil.setAlarm(WebBrowserActivity.this, CalendarUtil.tranceLong(endTime), title, content);
                }
            }
        }
    	
    

      

  • 相关阅读:
    嵌入式系统移植三部曲 王晓峰
    嵌入式系统移植三部曲 李炎朔
    ser and client.c 王晓峰
    李炎朔 编程分析
    嵌入式系统移植三步曲 赵晓晓
    嵌入式系统移植三步曲 孟明明
    现在 搞技术确实越来越不值钱了
    Linux C局域网通信程序 刘志卿
    Firefox全面兼容中国银联“在线支付”
    Linux常识型试题
  • 原文地址:https://www.cnblogs.com/hzwcoming/p/5762143.html
Copyright © 2011-2022 走看看