コード例 #1
0
ファイル: DetailActivity.java プロジェクト: argszero/Wuyun
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_detail);
   this.webView = ((WebView) findViewById(R.id.webView));
   this.webView.getSettings().setJavaScriptEnabled(true);
   this.webView.addJavascriptInterface(this, "backend");
   this.webView.setWebChromeClient(new WebChromeClient() {});
   this.webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
   this.webView.requestFocus();
   this.webView.setWebViewClient(new MyWebViewClient());
   this.webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
   int id = getIntent().getIntExtra("articleId", 0);
   this.webView.getSettings().setDefaultTextEncodingName("utf-8");
   try {
     String html = Db.get().readHtml("article/id/" + id, "html.html");
     //            this.webView.loadDataWithBaseURL(Db.get().getBaseUrl("article/id/" + id),html,
     // "text/html", "utf-8",null);
     this.webView.loadUrl(Db.get().getBaseUrl("article/id/" + id) + "/html.html");
   } catch (IOException e) {
     this.webView.loadData("已删除", "text/html; charset=UTF-8", null);
   }
 }
コード例 #2
0
ファイル: WuyunActivity.java プロジェクト: argszero/Wuyun
 @SuppressLint("JavascriptInterface")
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   File dir = this.getExternalFilesDir(null);
   if (dir == null) {
     dir = this.getFilesDir();
   }
   Db.get().init(dir.toString());
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_wuyun);
   this.webView = ((WebView) findViewById(R.id.webView));
   this.webView.getSettings().setJavaScriptEnabled(true);
   this.webView.addJavascriptInterface(new MyJavaScriptInterface(this), "backend");
   this.webView.setWebChromeClient(new WebChromeClient() {});
   this.webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
   this.webView.requestFocus();
   this.webView.setWebViewClient(new MyWebViewClient(null));
   this.webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
   this.webView.loadUrl("file:///android_asset/index.html");
   new PollingService.PollingThread().start();
   PollingUtils.startPollingService(this, 600, PollingService.class, PollingService.ACTION);
 }