Commit 21b5253f by gao.chao

web优化

parent fc1d4efe
......@@ -150,7 +150,7 @@ public class BaseWebActivity extends BaseActivity {
if (TextUtils.isEmpty(url)) {
return;
}
if (url.contains("isNeedBackButton")) {
if (url.contains("isNeedBackButton=true")) {
title.setVisibility(View.VISIBLE);
} else {
title.setVisibility(View.GONE);
......@@ -216,7 +216,6 @@ public class BaseWebActivity extends BaseActivity {
public void takePhoto() {
StringBuilder fileName = new StringBuilder();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileName.append(System.currentTimeMillis()).append("_upload.jpg");
File tempFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
......@@ -257,12 +256,11 @@ public class BaseWebActivity extends BaseActivity {
handler.post(new Runnable() {
@Override
public void run() {
webView.loadUrl("javascript:appCallJs.invoking;(" + method + "," + data + ")");
webView.loadUrl("javascript:appCallJs(" + method + "," + data + ")");
}
});
}
@JavascriptInterface
public void invoking(final String method, final String data) {
handler.post(new Runnable() {
......@@ -273,7 +271,12 @@ public class BaseWebActivity extends BaseActivity {
webView.clearHistory();
webView.clearFormData();
} else if (TextUtils.equals("goCallPhone", method)) {//去打电话
SystemUtil.makePhoneCall(BaseWebActivity.this, data);
try {
JSONObject jsonObject=new JSONObject(data);
SystemUtil.makePhoneCall(BaseWebActivity.this, jsonObject.optString("tel"));
} catch (JSONException e) {
e.printStackTrace();
}
} else if (TextUtils.equals("backPage", method)) {//返回上一页
webPageBack();
} else if (TextUtils.equals("goPage", method)) {//跳转原生页面
......@@ -286,7 +289,8 @@ public class BaseWebActivity extends BaseActivity {
appCallJs("setUserInfo", SpUtil.get(Key.USER_INFO, ""));
} else if (TextUtils.equals("sendSMS", method)) {//发送短信
sendSMS(data);
} else if (TextUtils.equals("location", method)) {//定位
}
// else if (TextUtils.equals("location", method)) {//定位
// LocationUtils.startLocation(BaseWebActivity.this, new LocationUtils.LocationCallback() {
// @Override
// public void onFail(String msg) {
......@@ -298,7 +302,7 @@ public class BaseWebActivity extends BaseActivity {
// appCallJs("LocationSuccess", JSON.toJSONString(bean));
// }
// });
}
// }
}
});
}
......@@ -326,20 +330,20 @@ public class BaseWebActivity extends BaseActivity {
} catch (JSONException e) {
e.printStackTrace();
}
if (TextUtils.equals(pageName, "MapLocation")) {//地图定位页面
// if (TextUtils.equals(pageName, "MapLocation")) {//地图定位页面
// Intent intent = new Intent(this, MapLocationActivity.class);
// startActivityForResult(intent, RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE);
} else {
// } else {
if (webListener != null) {
webListener.goPageListener(pageName, parameter);
}
}
// }
}
private void initWebView() {
WebSettings settings = webView.getSettings();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(2);
settings.setMixedContentMode(0);
}
settings.setBlockNetworkImage(false);
......@@ -357,7 +361,7 @@ public class BaseWebActivity extends BaseActivity {
settings.setDefaultTextEncodingName("utf-8");
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setAllowFileAccess(true);
settings.setAppCacheEnabled(true);
webView.setHorizontalScrollBarEnabled(false);//水平不显示
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment