【android与H5】书史足自悦,安用勤与劬。这篇文章主要讲述android与H5相关的知识,希望能为你提供帮助。
public class LuckyDrawClickActivity extends BaseActivity< LuckyDrawClickPresenter> implements LuckyDrawClickContract.View {
private WebView webView;
private String id;
@Override
public void setDaggerComponent(@NonNull AppComponent appComponent) {
DaggerLuckyDrawClickComponent // 如找不到该类,请编译一下项目
.builder()
.appComponent(appComponent)
.luckyDrawClickModule(new LuckyDrawClickModule(this))
.build()
.inject(this);
}
public static void launchActivity(Activity activity, String id) {
Intent intent = new Intent(activity, LuckyDrawClickActivity.class);
intent.putExtra("id", id);
activity.startActivity(intent);
}
@Override
public int initLayout(@Nullable Bundle savedInstanceState) {
return R.layout.activity_lucky_draw_click;
}
@Override
public void init(@Nullable Bundle savedInstanceState) {
webView = (WebView) findViewById(R.id.wv_webview);
id = getIntent().getStringExtra("id");
loadWeb();
}
//@SuppressLint("javascriptInterface")
//public void loadWeb() {
////String url = "https://www.baidu.com/";
////String url = "file:///android_asset/index.html";
//String url = "http://192.168.2.92:8081/index.html";
////此方法可以在webview中打开链接而不会跳转到外部浏览器
//webView.getSettings().setjavaScriptEnabled(true);
//webView.loadUrl(url);
//
//webView.setWebViewClient(new WebViewClient() {
//@Override
//public void onPageFinished(WebView view, String url) {
//super.onPageFinished(view, url);
////view.loadUrl("javascript:getDrawsRemainder("" + "1" + "")");
//view.loadUrl("javascript:get()");
//}
//});
//}
@SuppressLint("JavascriptInterface")
public void loadWeb() {
String url = "http://192.168.2.92:8081/index.html";
//此方法可以在webview中打开链接而不会跳转到外部浏览器
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
//支持弹窗,也就是支持html网页弹框
webView.setWebChromeClient(new WebChromeClient() {
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
return super.onJsAlert(view, url, message, result);
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//view.loadUrl("javascript:getDrawsRemainder("" + "1" + "")");
view.loadUrl("javascript:getInit(" + id + ")");
}
});
//支持html中javascript解析,不管是不是js和android交互,只要网页中含有js都要
webView.getSettings().setJavaScriptEnabled(true);
}
//重载onKeyDown的函数,使其在页面内回退,而不是直接退出程序
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK & & webView.canGoBack()) {
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
/**
* 默认请求网络数据方法
*/
@Override
public void onRequest() {
}
/**
* p层返回数据
*/
@Override
public void showSuccessData(LuckyDrawClickResponse response) {
}
}
推荐阅读
- uni-app运行到手机报错Component constructors should be called while initialization. A constructor call has
- android Q(10) 拍照相机 照片存入失败
- android studio 入门坑
- iphone上传拍照图片时图片会旋转90度,从相册选择就不会,安卓手机也不会,怎么解决()
- Sapphire: Copying GC Without Stopping the World
- Android(裁剪系统预置应用)
- Android的四大组件及Activity 的生命周期 及五种布局
- Android架构设计(会话管理)
- 应用程序池DefaultAppPool提供服务的进程关闭时间超过了限制的解决办法