|
|
@@ -1,544 +0,0 @@ |
|
|
|
package cn.zhios.zhiying_base_widget; |
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.RequiresApi; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
import androidx.core.app.ActivityCompat; |
|
|
|
import androidx.core.content.ContextCompat; |
|
|
|
|
|
|
|
import android.Manifest; |
|
|
|
import android.app.Activity; |
|
|
|
import android.content.ComponentName; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.pm.PackageInfo; |
|
|
|
import android.content.pm.PackageManager; |
|
|
|
import android.graphics.Color; |
|
|
|
import android.graphics.drawable.ColorDrawable; |
|
|
|
import android.net.Uri; |
|
|
|
import android.os.Build; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.util.Log; |
|
|
|
import android.view.KeyEvent; |
|
|
|
import android.view.MotionEvent; |
|
|
|
import android.view.View; |
|
|
|
import android.view.WindowManager; |
|
|
|
import android.webkit.GeolocationPermissions; |
|
|
|
import android.webkit.WebChromeClient; |
|
|
|
import android.webkit.WebSettings; |
|
|
|
import android.webkit.WebView; |
|
|
|
import android.webkit.WebViewClient; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.ProgressBar; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
|
|
public class WebViewActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
WebView webview; |
|
|
|
ImageView back; |
|
|
|
ImageView refresh; |
|
|
|
|
|
|
|
ProgressBar progressBar; |
|
|
|
|
|
|
|
TextView tvTitle; |
|
|
|
|
|
|
|
Boolean isRequestPre = false; |
|
|
|
String url; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
setContentView(R.layout.activity_web_view); |
|
|
|
getWindow().setStatusBarColor(Color.TRANSPARENT); |
|
|
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); |
|
|
|
url = getIntent().getStringExtra("url"); |
|
|
|
Log.d("请求连接:", url); |
|
|
|
webview = findViewById(R.id.web); |
|
|
|
|
|
|
|
back = findViewById(R.id.iv_back); |
|
|
|
refresh = findViewById(R.id.iv_refresh); |
|
|
|
progressBar = findViewById(R.id.pg_bar); |
|
|
|
tvTitle = findViewById(R.id.tv_title); |
|
|
|
|
|
|
|
back.setOnClickListener( |
|
|
|
new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
if (webview.canGoBack()) { |
|
|
|
webview.goBack(); |
|
|
|
} else { |
|
|
|
isRequestPre = false; |
|
|
|
finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
refresh.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
webview.reload(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
WebSettings settings = webview.getSettings(); |
|
|
|
|
|
|
|
settings.setJavaScriptEnabled(true);//启用js |
|
|
|
|
|
|
|
settings.setJavaScriptCanOpenWindowsAutomatically(true);//js和android交互 |
|
|
|
|
|
|
|
// String cacheDirPath = PathCommonDefines.WEBVIEW_CACHE; |
|
|
|
// |
|
|
|
// settings.setAppCachePath(cacheDirPath); //设置缓存的指定路径 |
|
|
|
|
|
|
|
settings.setAllowFileAccess(true); // 允许访问文件 |
|
|
|
|
|
|
|
settings.setAppCacheEnabled(true); //设置H5的缓存打开,默认关闭 |
|
|
|
|
|
|
|
settings.setUseWideViewPort(true);//设置webview自适应屏幕大小 |
|
|
|
|
|
|
|
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);//设置,可能的话使所有列的宽度不超过屏幕宽度 |
|
|
|
|
|
|
|
settings.setLoadWithOverviewMode(true);//设置webview自适应屏幕大小 |
|
|
|
|
|
|
|
settings.setDomStorageEnabled(true);//设置可以使用localStorage |
|
|
|
|
|
|
|
settings.setSupportZoom(false);//关闭zoom按钮 |
|
|
|
|
|
|
|
settings.setBuiltInZoomControls(false);//关闭zoom |
|
|
|
|
|
|
|
settings.setGeolocationEnabled(true); |
|
|
|
|
|
|
|
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); |
|
|
|
|
|
|
|
webview.setVerticalScrollBarEnabled(false); |
|
|
|
|
|
|
|
// |
|
|
|
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { |
|
|
|
// webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); |
|
|
|
// |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
webview.setWebViewClient(new WebViewClient() { |
|
|
|
@Override |
|
|
|
public boolean shouldOverrideUrlLoading(WebView view, String url) { |
|
|
|
Log.d("WEB重定向", url); |
|
|
|
if (WebViewActivity.this.isFinishing()) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
Intent intent2 = new Intent(); |
|
|
|
intent2.putExtra("url", url); |
|
|
|
WebViewActivity.this.setResult(20210501, intent2); |
|
|
|
|
|
|
|
if (url.startsWith("http://") || url.startsWith("https://")) { |
|
|
|
|
|
|
|
} else { |
|
|
|
try { |
|
|
|
/** |
|
|
|
* 统一的scheme协议打开第三方app,若出错说明没有安装该app |
|
|
|
* 捕获到错误后不继续加载该url以免加载出错 |
|
|
|
*/ |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
startActivity(intent); |
|
|
|
return true; |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (url.startsWith("tel:")) { |
|
|
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.startsWith("bdnetdisk:")) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("vipshop://")) {//打开唯品会 |
|
|
|
if (isAvilible(WebViewActivity.this, "com.achievo.vipshop")) { |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
startActivity(intent); |
|
|
|
} else { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装唯品会app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("androidamap://")) { |
|
|
|
if (isAvilible(WebViewActivity.this, "com.autonavi.minimap")) { |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
startActivity(intent); |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装高德地图app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (url.contains("didapinche://")) { |
|
|
|
if (isAvilible(WebViewActivity.this, "com.didapinche.booking")) { |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
startActivity(intent); |
|
|
|
} else { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装滴答出行app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (url.contains("tmast://")) { |
|
|
|
try { |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
startActivity(intent); |
|
|
|
} catch (Exception e) { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装应用宝app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.startsWith("http://ditu.amap.com") || |
|
|
|
url.startsWith("https://ditu.amap.com")) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
//品牌店家点击商品,请求接口进行相应的跳转 |
|
|
|
if (url.contains("h5.m.taobao.com/awp/core/detail") || url.contains("detail.m.tmall.com/item.htm") |
|
|
|
|| url.contains("item.m.jd.com/product") || (url.contains("item.m.jd.com/ware/view.action") |
|
|
|
|| url.contains("wareId=") || url.contains("h5.m.taobao.com/trip/travel-detail/index/index.htm")) |
|
|
|
|| url.contains("detail.tmall.hk/hk") || url.contains("vip.com/product") |
|
|
|
|| url.contains("suning.com/product") || url.contains("kaola.com/product") |
|
|
|
|| url.contains("yangkeduo.com/goods")) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
if (url.contains("tbopen://") || url.contains("tmall://") || url.contains("taobaotravel://")) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("openapp.jdmobile:")) { |
|
|
|
//打开京东app |
|
|
|
if (isAvilible(WebViewActivity.this, "com.jingdong.app.mall")) { |
|
|
|
|
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("pinduoduo://com.xunmeng.pinduoduo")) { |
|
|
|
if (isAvilible(WebViewActivity.this, "com.xunmeng.pinduoduo")) { |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
startActivity(intent); |
|
|
|
} else { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装拼多多app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("imeituan://")) {//打开美团 |
|
|
|
if (isAvilible(WebViewActivity.this, "com.sankuai.meituan")) { |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
startActivity(intent); |
|
|
|
} else { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装美团app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("suning://")) { |
|
|
|
if (isAvilible(WebViewActivity.this, "com.suning.mobile.ebuy")) { |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
startActivity(intent); |
|
|
|
} else { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装苏宁app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("kaola://")) { |
|
|
|
if (isAvilible(WebViewActivity.this, "com.kaola")) { |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
startActivity(intent); |
|
|
|
} else { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装考拉app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("dianping://")) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("aliim:")) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("?mod=appapi&act=miandan_course&ctrl=close")) { |
|
|
|
finish(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("vipma.net/quickapp.html?")) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (url.contains("cxcwallet://")) { |
|
|
|
if (isAvilible(WebViewActivity.this, "com.cxcblock.wallet")) {//传入指定应用包名 |
|
|
|
Intent intent = new Intent(); |
|
|
|
intent.setData(Uri.parse(url)); |
|
|
|
startActivity(intent); |
|
|
|
} else { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装CXCapp", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如下方案可在非微信内部WebView的H5页面中调出微信支付 |
|
|
|
if (url.startsWith("weixin://wap/pay?")) { |
|
|
|
try { |
|
|
|
Intent intent = new Intent(); |
|
|
|
intent.setAction(Intent.ACTION_VIEW); |
|
|
|
intent.setData(Uri.parse(url)); |
|
|
|
startActivity(intent); |
|
|
|
return true; |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装微信app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.startsWith("weixin://")) { |
|
|
|
try { |
|
|
|
Intent intent = new Intent(); |
|
|
|
intent.setAction(Intent.ACTION_VIEW); |
|
|
|
intent.setData(Uri.parse(url)); |
|
|
|
startActivity(intent); |
|
|
|
return true; |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装微信app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.endsWith("native://wechat")) { |
|
|
|
Intent intent = new Intent(); |
|
|
|
ComponentName cmp = new ComponentName("com.tencent.mm", "com.tencent.mm.ui.LauncherUI"); |
|
|
|
intent.setAction(Intent.ACTION_MAIN); |
|
|
|
intent.addCategory(Intent.CATEGORY_LAUNCHER); |
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
|
|
|
intent.setComponent(cmp); |
|
|
|
startActivity(intent); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// if (url.contains("navite://save#")) { |
|
|
|
// String[] split = url.split("navite://save#"); |
|
|
|
// SDFileHelper sdFileHelper = new SDFileHelper(mActivity); |
|
|
|
// sdFileHelper.setOnDownloadFinishListener(new SDFileHelper.OnDownloadFinishListener() { |
|
|
|
// @Override |
|
|
|
// public void onDownloadFinish(String filePath) { |
|
|
|
// ToastUtils.showShort("图片已保存到内存卡根目录" + AppUtil.getAppName() + "文件夹中"); |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// sdFileHelper.savePicture("we_chat_qr_code" + ".jpg", split[1], true); |
|
|
|
// return true; |
|
|
|
// } |
|
|
|
//不拦截的话绑定淘宝关系id的时候会因为下面login.m.taobao.com的拦截而唤醒手淘授权之后导致不能切换帐号 |
|
|
|
// if (url.contains("client_id") && url.contains("login.m.taobao.com/logout.htm?")) { |
|
|
|
// view.loadUrl(url); |
|
|
|
// return true; |
|
|
|
// } |
|
|
|
if (url.contains("client_id")) { |
|
|
|
view.loadUrl(url); |
|
|
|
return true; |
|
|
|
} |
|
|
|
// if (url.contains("login.m.taobao.com")) { |
|
|
|
// AliLoginMethodUtil.AliLoginMethod(new AliLoginMethodUtil.AliLoginListener() { |
|
|
|
// @Override |
|
|
|
// public void loginSuccess(String s, String s1, Session session) { |
|
|
|
// |
|
|
|
// } |
|
|
|
// |
|
|
|
// @Override |
|
|
|
// public void LoginFail(int i, String s) { |
|
|
|
// |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// return true; |
|
|
|
// } |
|
|
|
|
|
|
|
if (url.contains("alipays://platformapi")) { |
|
|
|
if (checkAliPayInstalled()) { |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
|
|
startActivity(intent); |
|
|
|
// finish(); |
|
|
|
} else { |
|
|
|
Toast.makeText(WebViewActivity.this, "请先安装支付宝app", Toast.LENGTH_SHORT).show(); |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (url.contains("intent://go/ju/webview?")) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (url.contains("deterorder")) { |
|
|
|
webview.loadUrl(url); |
|
|
|
return true; |
|
|
|
} |
|
|
|
if (getIntent().getBooleanExtra("isSearchEnter", false) && url.contains("sku=")) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return !(url.startsWith("http://") || url.startsWith("https://")); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onLoadResource(WebView view, String url) { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onPageFinished(WebView view, String url) { |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
webview.setWebChromeClient(new WebChromeClient() { |
|
|
|
@Override |
|
|
|
synchronized public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { |
|
|
|
callback.invoke(origin, true, false); |
|
|
|
// if (!isRequestPre) { |
|
|
|
// isRequestPre = true; |
|
|
|
// quanxian(WebViewActivity.this); |
|
|
|
// } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onProgressChanged(WebView view, int newProgress) { |
|
|
|
super.onProgressChanged(view, newProgress); |
|
|
|
progressBar.setProgress(newProgress); |
|
|
|
if (newProgress == 100) { |
|
|
|
progressBar.setVisibility(View.GONE); |
|
|
|
} else { |
|
|
|
progressBar.setVisibility(View.VISIBLE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onReceivedTitle(WebView view, String title) { |
|
|
|
super.onReceivedTitle(view, title); |
|
|
|
if (title != null && title.length() != 0) { |
|
|
|
tvTitle.setText(title); |
|
|
|
} else { |
|
|
|
tvTitle.setText(url); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
webview.loadUrl(url); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 检测是否安装支付宝app |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public boolean checkAliPayInstalled() { |
|
|
|
Uri uri = Uri.parse("alipays://platformapi/startApp"); |
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri); |
|
|
|
ComponentName componentName = intent.resolveActivity(getPackageManager()); |
|
|
|
return componentName != null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 检查手机上是否安装了指定的软件 |
|
|
|
* |
|
|
|
* @param context |
|
|
|
* @param packageName:应用包名 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private boolean isAvilible(Context context, String packageName) { |
|
|
|
//获取packagemanager |
|
|
|
final PackageManager packageManager = context.getPackageManager(); |
|
|
|
//获取所有已安装程序的包信息 |
|
|
|
List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0); |
|
|
|
//用于存储所有已安装程序的包名 |
|
|
|
List<String> packageNames = new ArrayList<String>(); |
|
|
|
//从pinfo中将包名字逐一取出,压入pName list中 |
|
|
|
if (packageInfos != null) { |
|
|
|
for (int i = 0; i < packageInfos.size(); i++) { |
|
|
|
String packName = packageInfos.get(i).packageName; |
|
|
|
packageNames.add(packName); |
|
|
|
} |
|
|
|
} |
|
|
|
//判断packageNames中是否有目标程序的包名,有TRUE,没有FALSE |
|
|
|
return packageNames.contains(packageName); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 检查是否安装手机淘宝 |
|
|
|
* |
|
|
|
* @param context |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
|
|
|
|
public static boolean isInstallTaoBao(Context context) { |
|
|
|
PackageInfo packageInfo = null; |
|
|
|
try { |
|
|
|
packageInfo = context.getPackageManager().getPackageInfo("com.taobao.taobao", 0); |
|
|
|
} catch (Exception e) { |
|
|
|
packageInfo = null; |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
if (packageInfo == null) { |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
///检查并请求定位权限 |
|
|
|
public void quanxian(final Activity context) { |
|
|
|
Log.d("权限请求", "------------"); |
|
|
|
try { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
|
|
|
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { |
|
|
|
Log.d("权限请求", "无定位权限------------"); |
|
|
|
ActivityCompat.requestPermissions(context, |
|
|
|
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 20210422); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SecurityException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) { |
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK) { |
|
|
|
if (webview.canGoBack()) { |
|
|
|
webview.goBack(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
isRequestPre = true; |
|
|
|
} |
|
|
|
return super.onKeyDown(keyCode, event); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
|
|
|
if (requestCode == 20210422) { |
|
|
|
Log.d("权限请求", "定位权限回调------------"); |
|
|
|
webview.clearCache(true); |
|
|
|
webview.loadUrl(url); |
|
|
|
return; |
|
|
|
} |
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onDestroy() { |
|
|
|
super.onDestroy(); |
|
|
|
webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); |
|
|
|
webview.destroy(); |
|
|
|
} |
|
|
|
} |