隐私政策拦截

This commit is contained in:
lijia 2024-11-22 15:55:20 +08:00
parent 65994b8eda
commit c6005ee9a1
7 changed files with 361 additions and 73 deletions

View File

@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.arpa.hndahesudintocctmsdriver">
<uses-permission android:name="android.permission.CALL_PHONE" />
<!-- 白名单 -->
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
@ -71,14 +72,14 @@
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait" ></activity>
android:screenOrientation="portrait"></activity>
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.wallet.WithdrawalActivity"
android:screenOrientation="portrait" />
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.wallet.UpBankActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.OrderAllActivity"
android:screenOrientation="portrait" />
@ -93,11 +94,11 @@
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.auth.PhotoCarActivity"
android:windowSoftInputMode="adjustPan|stateHidden"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.auth.VehicleAuthActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.shangchuan.ShangChuangImgActivity"
android:screenOrientation="portrait">
@ -142,13 +143,13 @@
</activity>
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.shangchuan.GetShangChuanActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.auth.AuthQualificationActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.OrderListActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.HuoYunDelActivity"
android:screenOrientation="portrait">
@ -161,14 +162,14 @@
</activity>
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.auth.CertificatesActivity"
android:windowSoftInputMode="adjustPan|stateHidden"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.auth.AddCarSuccActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.login.LoginActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.login.WelcomeActivity"
android:exported="true"
@ -192,10 +193,10 @@
</activity>
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.drivercircle.VideoReleaseActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.shangchuan.WebPDFActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.StartYunDanActivity"
android:screenOrientation="portrait">
@ -203,17 +204,21 @@
</activity>
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.drivercircle.HomePageActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.alert.VehicleChoiceActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.home.shangchuan.OrderComplaintActivity"
android:screenOrientation="portrait"/>
android:screenOrientation="portrait" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.web.WebActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.web.WebOnlyOneActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity
android:name="com.arpa.hndahesudintocctmsdriver.ui.web.WebKfActivity"
android:screenOrientation="portrait"
@ -223,7 +228,7 @@
<activity
android:name=".ui.news.NewActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden" />
android:windowSoftInputMode="stateAlwaysHidden" />
<service
android:name="com.arpa.hndahesudintocctmsdriver.service.TrackService"
@ -266,7 +271,7 @@
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="${GAODEKEY}" />
<!-- android:value="702eaa84675618b8eb69298d9fd42ca3" />-->
<!-- android:value="702eaa84675618b8eb69298d9fd42ca3" />-->
<service android:name="com.amap.api.location.APSService"></service>
@ -362,10 +367,11 @@
<activity
android:name=".H5Activity"
android:screenOrientation="portrait"
android:launchMode="singleTask">
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
@ -383,10 +389,11 @@
<activity
android:name=".H5Activity2"
android:screenOrientation="portrait"
android:launchMode="singleTask">
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

View File

@ -41,6 +41,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.arpa.hndahesudintocctmsdriver.cuspop.SimCenterPop;
import com.arpa.hndahesudintocctmsdriver.event.FaceEvent;
import com.arpa.hndahesudintocctmsdriver.event.HomeEvent;
import com.arpa.hndahesudintocctmsdriver.request.UserRequset;
import com.arpa.hndahesudintocctmsdriver.ui.MainActivity;
import com.arpa.hndahesudintocctmsdriver.ui.UiAuxiliary;
import com.arpa.hndahesudintocctmsdriver.ui.auth.CertificatesActivity;
@ -249,7 +250,7 @@ public class H5Activity extends AppCompatActivity {
Uri uri = Uri.parse(url);
Log.e("test", "要加载的地址:" + uri.getScheme() + " " + url + " ");
if (uri.getScheme().equals("http") || uri.getScheme().equals("https")) {
if (isGoCar&&url.startsWith("http://agreement.dahehuoyun.com/#/1ba5c216/912f4c9587/5eb5184653/6ef9")){
if (isGoCar&&url.startsWith("https://agreement.dahehuoyun.com/#/1ba5c216/912f4c9587/5eb5184653/6ef9")){
isOk = true;
view.loadUrl(url);
new MessageUtils().showSimCenPop(ctx, "个人信息上传成功,请添加车辆信息!", "去添加",() -> {

View File

@ -14,6 +14,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import com.arpa.hndahesudintocctmsdriver.ui.web.WebOnlyOneActivity;
import com.lxj.xpopup.core.CenterPopupView;
import com.arpa.hndahesudintocctmsdriver.R;
import com.arpa.hndahesudintocctmsdriver.ui.web.WebActivity;
@ -68,7 +69,7 @@ public class AgreementAlert extends CenterPopupView {
@Override
public void onClick(View widget) {
//用户服务协议点击事件
Intent in=new Intent(getContext(), WebActivity.class);
Intent in=new Intent(getContext(), WebOnlyOneActivity.class);
in.putExtra("url",url2);
in.putExtra("title","用户服务协议");
getContext().startActivity(in);
@ -87,7 +88,7 @@ public class AgreementAlert extends CenterPopupView {
@Override
public void onClick(View widget) {
//用户服务协议点击事件
Intent in=new Intent(getContext(), WebActivity.class);
Intent in=new Intent(getContext(), WebOnlyOneActivity.class);
in.putExtra("url",url);
in.putExtra("title","隐私政策");
getContext().startActivity(in);

View File

@ -1,11 +1,13 @@
package com.arpa.hndahesudintocctmsdriver.ui.auth;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@ -35,6 +37,7 @@ import com.arpa.hndahesudintocctmsdriver.event.VehicleEvent;
import com.arpa.hndahesudintocctmsdriver.ui.wallet.UpBankActivity;
import com.arpa.hndahesudintocctmsdriver.util.MessageUtils;
import com.arpa.hndahesudintocctmsdriver.util.PickerUtils;
import com.arpa.hndahesudintocctmsdriver.util.PicturlUtil;
import com.arpa.hndahesudintocctmsdriver.util.alert.ToastUtil;
import com.arpa.hndahesudintocctmsdriver.util.map.MapUtil;
import com.bumptech.glide.Glide;
@ -85,6 +88,8 @@ import com.arpa.hndahesudintocctmsdriver.util.view.BaseAppCompatActivity;
import com.arpa.hndahesudintocctmsdriver.util.view.BaseRecyclerView;
import com.lxj.xpopup.photoview.PhotoView;
import com.lxj.xpopup.util.SmartGlideImageLoader;
import com.lxj.xpopup.util.XPermission;
import com.permissionx.guolindev.PermissionX;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@ -209,8 +214,6 @@ public class CertificatesActivity extends BaseAppCompatActivity {
key = true;
}, 3000);
}
} else {
Toast.makeText(con, bb.getMsg(), Toast.LENGTH_SHORT).show();
}
@ -221,12 +224,25 @@ public class CertificatesActivity extends BaseAppCompatActivity {
Log.e("url", CacheGroup.cacheList.get("authUrl"));
BaseBean bb = gson.fromJson(CacheGroup.cacheList.get("authUrl"), BaseBean.class);
if (bb.getCode() == 200) {
Intent intent = new Intent(this, H5Activity.class);
intent.putExtra("url", (String) bb.getData());
intent.putExtra("view_file", false);
intent.putExtra("title", "人脸识别");
intent.putExtra("isGoCar", true);
startActivity(intent);
PermissionX.init(this)
.permissions(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
.request((allGranted, grantedList, deniedList) -> {
if (allGranted) {
Intent intent = new Intent(this, H5Activity.class);
intent.putExtra("url", (String) bb.getData());
intent.putExtra("view_file", false);
intent.putExtra("title", "人脸识别");
intent.putExtra("isGoCar", true);
startActivity(intent);
} else {
new MessageUtils().showSimCenPop(act, "缺少相机,媒体权限,将无法为您提供服务,去开启!", "取消", "确认", () -> {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
act.startActivity(intent);
});
}
});
// EsignSdk.getInstance().startH5Activity(act, StringUtil.isNull(String.valueOf(bb.getData()), ""));
} else {
Toast.makeText(con, bb.getMsg(), Toast.LENGTH_LONG).show();
@ -280,22 +296,6 @@ public class CertificatesActivity extends BaseAppCompatActivity {
con.startActivity(in);
}
finish();
// if ("1".equals(needUpQCPhoto)) {
// //现逻辑上传行驶证信息后 判断是否跳转从业资格证
// Intent in = new Intent(con, AuthQualificationActivity.class);
// in.putExtra("type", "0");
// in.putExtra("isOverCar", false);
// in.putExtra("carId", String.valueOf(czb.getData().getCarId()));
// startActivity(in);
// } else {
// //原逻辑上传行驶证信息后 跳转车辆照片页面
// Intent in = new Intent(con, PhotoCarActivity.class);
// in.putExtra("type", 0);
// in.putExtra("carId", String.valueOf(czb.getData().getCarId()));
// con.startActivity(in);
// }
} else {
Toast.makeText(con, czb.getMsg(), Toast.LENGTH_SHORT).show();
}
@ -459,12 +459,25 @@ public class CertificatesActivity extends BaseAppCompatActivity {
Log.e("url", CacheGroup.cacheList.get("authUrl"));
BaseBean bb = gson.fromJson(CacheGroup.cacheList.get("authUrl"), BaseBean.class);
if (bb.getCode() == 200) {
Intent intent = new Intent(this, H5Activity.class);
intent.putExtra("url", (String) bb.getData());
intent.putExtra("view_file", false);
intent.putExtra("title", "人脸识别");
intent.putExtra("isGoCar", true);
startActivity(intent);
PermissionX.init(this)
.permissions(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA)
.request((allGranted, grantedList, deniedList) -> {
if (allGranted) {
Intent intent = new Intent(this, H5Activity.class);
intent.putExtra("url", (String) bb.getData());
intent.putExtra("view_file", false);
intent.putExtra("title", "人脸识别");
intent.putExtra("isGoCar", true);
startActivity(intent);
} else {
new MessageUtils().showSimCenPop(act, "缺少相机,媒体权限,将无法为您提供服务,去开启!", "取消", "确认", () -> {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
act.startActivity(intent);
});
}
});
// EsignSdk.getInstance().startH5Activity(act, StringUtil.isNull(String.valueOf(bb.getData()), ""));
} else {
Toast.makeText(con, bb.getMsg(), Toast.LENGTH_LONG).show();
@ -922,7 +935,7 @@ public class CertificatesActivity extends BaseAppCompatActivity {
value3.setText(ocb.getData().getAddress());
Glide.with(con).load(path).into(img1);
} else {
Toast.makeText(con, "识别失败", Toast.LENGTH_SHORT).show();
Toast.makeText(con, "识别失败请重新上传", Toast.LENGTH_SHORT).show();
}
CacheGroup.cacheList.remove(TYPE_NAME[0]);
}
@ -935,7 +948,7 @@ public class CertificatesActivity extends BaseAppCompatActivity {
//自动调取提交功能实现页面自动跳转
subimt();
} else {
Toast.makeText(con, "识别失败", Toast.LENGTH_SHORT).show();
Toast.makeText(con, "识别失败请重新上传", Toast.LENGTH_SHORT).show();
}
CacheGroup.cacheList.remove(TYPE_NAME_BANK[0]);
}
@ -954,7 +967,7 @@ public class CertificatesActivity extends BaseAppCompatActivity {
value4.setText(StringUtil.isNull(od.getEndDate(), "识别异常"));
Glide.with(con).load(path).into(img1);
} else {
Toast.makeText(con, "识别失败", Toast.LENGTH_SHORT).show();
Toast.makeText(con, "识别失败请重新上传", Toast.LENGTH_SHORT).show();
}
CacheGroup.cacheList.remove(TYPE_NAME[1]);
}
@ -965,7 +978,7 @@ public class CertificatesActivity extends BaseAppCompatActivity {
//自动调取提交功能实现页面自动跳转
subimt();
} else {
Toast.makeText(con, "识别失败", Toast.LENGTH_SHORT).show();
Toast.makeText(con, "识别失败请重新上传", Toast.LENGTH_SHORT).show();
}
CacheGroup.cacheList.remove(TYPE_NAME_BANK[1]);
}
@ -1006,7 +1019,7 @@ public class CertificatesActivity extends BaseAppCompatActivity {
new AuthRequest().getCarInfo(con, hd, olb.getData().getVclN());
Log.e("-cardId-", oCrcarId);
} else {
Toast.makeText(con, "识别失败", Toast.LENGTH_SHORT).show();
Toast.makeText(con, "识别失败请重新上传", Toast.LENGTH_SHORT).show();
}
CacheGroup.cacheList.remove(TYPE_NAME[2]);
}
@ -1020,7 +1033,7 @@ public class CertificatesActivity extends BaseAppCompatActivity {
//自动调取提交功能实现页面自动跳转实现页面自动跳转
subimt();
} else {
Toast.makeText(con, "识别失败", Toast.LENGTH_SHORT).show();
Toast.makeText(con, "识别失败请重新上传", Toast.LENGTH_SHORT).show();
}
CacheGroup.cacheList.remove(TYPE_NAME_BANK[2]);
}
@ -1119,8 +1132,18 @@ public class CertificatesActivity extends BaseAppCompatActivity {
switch (index) {
case 0:
if (ocb != null && ocbb != null) {
if (ocb.getData() == null) {
ToastUtils.showToast(con, "主页照片识别失败,请重新上传");
return;
}
if (ocbb == null || ocbb.getData() == null) {
ToastUtils.showToast(con, "副页照片识别失败,请重新上传");
return;
}
customDialog = new CustomDialog(con, "网络请求中...");
customDialog.show();
IDInputBean ib = new IDInputBean();
ib.setIdcarName(str1);
ib.setIdcard(str2);
@ -1143,8 +1166,20 @@ public class CertificatesActivity extends BaseAppCompatActivity {
//olb
//{"档案编号","初次领证日期","准驾车型","有效期限(止)"},
if (odl != null && odlb != null) {
if (odl.getData() == null) {
ToastUtils.showToast(con, "主页照片识别失败,请重新上传");
return;
}
if (odlb == null || odlb.getData() == null) {
ToastUtils.showToast(con, "副页照片识别失败,请重新上传");
return;
}
customDialog = new CustomDialog(con, "网络请求中...");
customDialog.show();
Log.e("ocr", new Gson().toJson(odl));
LicenseInputBean iib = new LicenseInputBean();
iib.setArchivesName(odlb.getData().getFileNumber());
@ -1182,6 +1217,17 @@ public class CertificatesActivity extends BaseAppCompatActivity {
// Toast.makeText(con, "请完善内容", Toast.LENGTH_SHORT).show();
// return;
// }
if (olb.getData() == null) {
ToastUtils.showToast(con, "主页照片识别失败,请重新上传");
return;
}
if (oblb == null || oblb.getData() == null) {
ToastUtils.showToast(con, "副页照片识别失败,请重新上传");
return;
}
customDialog = new CustomDialog(con, "网络请求中...");
customDialog.show();
HashMap<String, Object> map = new HashMap<>();
@ -1194,6 +1240,7 @@ public class CertificatesActivity extends BaseAppCompatActivity {
// map.put("ownerName", str3);
// map.put("vin", str4);//车辆识别代号
String carLong = "";
String carWidth = "";
String carHeight = "";
@ -1288,10 +1335,15 @@ public class CertificatesActivity extends BaseAppCompatActivity {
break;
case 3:
if (olb != null || (cdb != null && cdb.getRes() == 1)) {
// if (curEnergy==null){
// Toast.makeText(con,"请完善内容",Toast.LENGTH_SHORT).show();
// return;
// }
if (olb.getData() == null) {
ToastUtils.showToast(con, "主页照片识别失败,请重新上传");
return;
}
if (oblb == null || oblb.getData() == null) {
ToastUtils.showToast(con, "副页照片识别失败,请重新上传");
return;
}
customDialog = new CustomDialog(con, "网络请求中...");
customDialog.show();
// Map<String, Object> map = new HashMap<>();
@ -1328,7 +1380,6 @@ public class CertificatesActivity extends BaseAppCompatActivity {
// map.put("fileNumber", oblb.getData().getRecordId());//档案编号
// map.put("towAuality", oblb.getData().getVclDrwTn());//准牵引总质量
String carLong = "";
String carWidth = "";
String carHeight = "";

View File

@ -31,6 +31,7 @@ import com.arpa.hndahesudintocctmsdriver.parts.ConfigParts;
import com.arpa.hndahesudintocctmsdriver.request.net.BaseObserver;
import com.arpa.hndahesudintocctmsdriver.request.net.DataManager;
import com.arpa.hndahesudintocctmsdriver.request.net.RxHttpCallBack;
import com.arpa.hndahesudintocctmsdriver.ui.web.WebOnlyOneActivity;
import com.dahe.mylibrary.net.CommonResponseBean;
import com.google.gson.Gson;
import com.arpa.hndahesudintocctmsdriver.R;
@ -157,7 +158,7 @@ public class LoginActivity extends BaseActivity {
ConfigBean cb = ConfigParts.getConfigParts(con);
if (cb != null) {
url1 = cb.getData().getUserUrl();
url1 = "https://agreement.dahehuoyun.com/#/user";
url2 = "https://agreement.dahehuoyun.com/currency/#/";
}
TextView tv_content = findViewById(R.id.tv_content);
@ -171,7 +172,7 @@ public class LoginActivity extends BaseActivity {
public void onClick(View widget) {
Log.e("-用户服务协议-", url1);
//用户服务协议点击事件
Intent in = new Intent(con, WebActivity.class);
Intent in = new Intent(con, WebOnlyOneActivity.class);
in.putExtra("title", "用户服务协议");
in.putExtra("url", url1);
startActivity(in);
@ -191,7 +192,7 @@ public class LoginActivity extends BaseActivity {
@Override
public void onClick(View widget) {
//隐私协议点击事件
Intent in = new Intent(con, WebActivity.class);
Intent in = new Intent(con, WebOnlyOneActivity.class);
in.putExtra("title", "隐私政策");
in.putExtra("url", url2);
startActivity(in);

View File

@ -140,8 +140,8 @@ public class WelcomeActivity extends BaseAppCompatActivity {
new XPopup.Builder(con)
.dismissOnBackPressed(false)
.dismissOnTouchOutside(false)
.asCustom(new AgreementAlert(con, "http://agreement.dahehuoyun.com/currency/#/",
"http://agreement.dahehuoyun.com/rule/serviceAgreement/dist/index.html#/", hd))
.asCustom(new AgreementAlert(con, "https://agreement.dahehuoyun.com/currency/#/",
"https://agreement.dahehuoyun.com/#/user", hd))
.show();
}
Glide.with(con)

View File

@ -0,0 +1,227 @@
package com.arpa.hndahesudintocctmsdriver.ui.web;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import com.arpa.hndahesudintocctmsdriver.R;
import com.arpa.hndahesudintocctmsdriver.bean.UserBean;
import com.arpa.hndahesudintocctmsdriver.parts.UserParts;
import com.arpa.hndahesudintocctmsdriver.util.PaxWebChromeClient;
import com.arpa.hndahesudintocctmsdriver.util.statusbar.StateStyleUtil;
import com.arpa.hndahesudintocctmsdriver.util.string.StringUtil;
import com.arpa.hndahesudintocctmsdriver.util.view.BaseActivity;
/**
* @author hlh
* @version 1.0.0
* @date 2021/8/6 16:48
* @description:访问webview的activity
*/
public class WebOnlyOneActivity extends BaseActivity {
private String url = "";
private String title = "";
private WebView wv;
private TextView title_tv;
private PaxWebChromeClient chromeClient;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StateStyleUtil.stateTextColor(this);
setContentView(R.layout.activity_web);
con = this;
initHardwareAccelerate();
wv = findViewById(R.id.wv);
title_tv = findViewById(R.id.title);
Intent in = getIntent();
url = in.getExtras().getString("url");
title = in.getExtras().getString("title");
chromeClient = new PaxWebChromeClient(this, null, null);
if ("咨询建议".equals(title)) {
initOpinion();
} else {
initView(null);
}
}
private void initHardwareAccelerate() {
try {
if (Integer.parseInt(Build.VERSION.SDK) >= 11) {
getWindow()
.setFlags(
android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
}
} catch (Exception e) {
}
}
@SuppressLint({"JavascriptInterface", "SetJavaScriptEnabled"})
@Override
public void initView(Object obj) {
super.initView(obj);
WebSettings webSettings = wv.getSettings();
//设置网页有缓存的时候也继续读取新的地址
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setDefaultTextEncodingName("utf-8");
// 特别注意5.1以上默认禁止了https和http混用以下方式是开启
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
wv.addJavascriptInterface(new JavaScriptObject(con), "webObj");
//PaxWebChromeClient chromeClient=new PaxWebChromeClient();
//WebView加载web资源
//覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为使网页用WebView打开
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url1) {
//返回值是true的时候控制去WebView打开为false调用系统浏览器或第三方浏览器
Log.d("test", "webactivity..url:" + url);
// if(!url.startsWith("http"))
// {
// Log.d("test","非http开头..url:"+url);
// Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
// boolean isInstall = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size()>0;
// Log.d("test","是否安装要跳转的app:"+isInstall);
// if(isInstall)
// {
// startActivity(intent);
// finish();
// }
// return true;
// }
if (!url1.equals(url))
return true;
wv.loadUrl(url1);
return true;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
handler.proceed();
}
});
wv.setWebChromeClient(chromeClient);
wv.loadUrl(url);
title_tv.setText(title);
}
public void initOpinion() {
if (findViewById(R.id.return_btn) != null) {
findViewById(R.id.return_btn).setOnClickListener(v -> {
finish();
});
}
title_tv.setText(title);
UserBean ub = UserParts.getUser(con);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setDomStorageEnabled(true); // 这个要加上
String openid = ub.getData().getUname(); // 用户的openid
String nickname = StringUtil.isNull(ub.getData().getRname(), "游客"); // 用户的nickname
String headimgurl = StringUtil.isNull(ub.getData().getHeadportraitUrl(), ""); // 用户的头像url
/* 获得 webview url请注意url单词是product而不是productsproducts是旧版本的参数用错地址将不能成功提交 */
String url = "https://support.qq.com/products/335639"; // 把1221数字换成你的产品ID否则会不成功
/* 准备post参数 */
String postData = "nickname=" + nickname + "&avatar=" + headimgurl + "&openid=" + openid;
wv.postUrl(url, postData.getBytes());
wv.setWebChromeClient(chromeClient);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return super.shouldOverrideUrlLoading(view, request);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//返回值是true的时候控制去WebView打开为false调用系统浏览器或第三方浏览器
view.loadUrl(url);
return true;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
handler.proceed();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
chromeClient.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
public class JavaScriptObject {
Context mContxt;
public JavaScriptObject(Context mContxt) {
this.mContxt = mContxt;
}
@JavascriptInterface
public void getName() {
Log.e("eeee-", "name");
Toast.makeText(con, "hello", Toast.LENGTH_SHORT).show();
}
@JavascriptInterface
public String getUserToken() {
// Log.e("-token-",UserParts.getUser(con).getData().getToken());
// return "woshitoken-androidfasdf";
return UserParts.getUser(con).getData().getToken();
}
@JavascriptInterface
public void isSuccess() {
finish();
}
@JavascriptInterface
public void isPdfSuccess() {
Toast.makeText(con, "签署成功", Toast.LENGTH_SHORT).show();
finish();
}
}
}