正在查看: 新暖心缘 v8.1.1 应用的 WebActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 新暖心缘 v8.1.1 应用的 WebActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.luanxingyuan.app.activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.JsResult;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.core.content.FileProvider;
import com.luanxingyuan.app.base.AppManager;
import com.luanxingyuan.app.base.BaseActivity;
import com.tencent.open.SocialConstants;
import com.yalantis.ucrop.util.FileUtils;
import java.io.File;
public class WebActivity extends BaseActivity {
private static final String[] PERMISSIONS = {"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"};
private static final int REQUEST_CODE_FILE_CHOOSER = 1;
private String mCameraFilePath;
private ValueCallback<Uri> mUploadCallBack;
private ValueCallback<Uri[]> mUploadCallBackAboveL;
private String url;
private WebChromeClient webChromeClient = new a();
private WebViewClient webViewClient = new b();
private WebView webview;
class a extends WebChromeClient {
a() {
}
@Override
public boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) {
return super.onJsAlert(webView, str, str2, jsResult);
}
@Override
public void onProgressChanged(WebView webView, int i8) {
super.onProgressChanged(webView, i8);
}
@Override
public void onReceivedTitle(WebView webView, String str) {
super.onReceivedTitle(webView, str);
}
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
WebActivity.this.mUploadCallBackAboveL = valueCallback;
WebActivity.this.showFileChooser();
return true;
}
}
class b extends WebViewClient {
b() {
}
@Override
public void onPageFinished(WebView webView, String str) {
super.onPageFinished(webView, str);
}
@Override
public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
StringBuilder sb = new StringBuilder();
sb.append("当前webview加载url == ");
sb.append(str);
super.onPageStarted(webView, str, bitmap);
}
@Override
public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
super.onReceivedError(webView, webResourceRequest, webResourceError);
}
@Override
public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
sslErrorHandler.proceed();
}
@Override
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
if (webResourceRequest.getUrl() == null) {
return false;
}
String uri = webResourceRequest.getUrl().toString();
try {
if (!uri.startsWith("weixin://") && !uri.startsWith("alipays://") && !uri.startsWith("mailto://") && !uri.startsWith("tel://")) {
webView.loadUrl(uri);
return true;
}
WebActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(uri)));
return true;
} catch (Exception unused) {
return false;
}
}
}
private void clearUploadMessage() {
ValueCallback<Uri[]> valueCallback = this.mUploadCallBackAboveL;
if (valueCallback != null) {
valueCallback.onReceiveValue(null);
this.mUploadCallBackAboveL = null;
}
ValueCallback<Uri> valueCallback2 = this.mUploadCallBack;
if (valueCallback2 != null) {
valueCallback2.onReceiveValue(null);
this.mUploadCallBack = null;
}
}
private void initUi() {
WebView webView = (WebView) findViewById(k7.a.f14812a);
this.webview = webView;
webView.setWebChromeClient(this.webChromeClient);
this.webview.setWebViewClient(this.webViewClient);
WebSettings settings = this.webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setLoadsImagesAutomatically(true);
settings.setDomStorageEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMixedContentMode(2);
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
}
private boolean isPermission() {
boolean z7 = false;
for (String str : PERMISSIONS) {
if (q.c.a(this, str) != 0) {
z7 = true;
}
}
return z7;
}
public void showFileChooser() {
if (isPermission()) {
androidx.core.app.c.l(this, PERMISSIONS, 300);
return;
}
Intent intent = new Intent("android.intent.action.GET_CONTENT");
intent.addCategory("android.intent.category.OPENABLE");
intent.setType("*/*");
Intent intent2 = new Intent("android.media.action.IMAGE_CAPTURE");
this.mCameraFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + System.currentTimeMillis() + ".jpg";
if (Build.VERSION.SDK_INT >= 24) {
intent2.putExtra("output", FileProvider.getUriForFile(this, getApplicationInfo().packageName + ".fileProvider", new File(this.mCameraFilePath)));
} else {
intent2.putExtra("output", Uri.fromFile(new File(this.mCameraFilePath)));
}
Intent intent3 = new Intent("android.intent.action.CHOOSER");
intent3.putExtra("android.intent.extra.TITLE", "File Chooser");
intent3.putExtra("android.intent.extra.INTENT", intent);
intent3.putExtra("android.intent.extra.INITIAL_INTENTS", new Intent[]{intent2});
startActivityForResult(intent3, 1);
}
@Override
protected View getContentView() {
return inflate(2131492984);
}
@Override
protected void onActivityResult(int i8, int i9, Intent intent) {
super.onActivityResult(i8, i9, intent);
if (i8 == 1) {
Uri data = (intent == null || i9 != -1) ? null : intent.getData();
if (data == null && !TextUtils.isEmpty(this.mCameraFilePath)) {
File file = new File(this.mCameraFilePath);
if (file.exists()) {
data = Uri.fromFile(file);
sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE", data));
}
}
if (data != null) {
String path = FileUtils.getPath(this, data);
if (!TextUtils.isEmpty(path)) {
File file2 = new File(path);
if (file2.exists() && file2.isFile()) {
Uri fromFile = Uri.fromFile(file2);
ValueCallback<Uri[]> valueCallback = this.mUploadCallBackAboveL;
if (valueCallback != null && fromFile != null) {
valueCallback.onReceiveValue(new Uri[]{fromFile});
this.mUploadCallBackAboveL = null;
return;
}
}
}
}
clearUploadMessage();
}
}
@Override
protected void onContentAdded() {
initUi();
String stringExtra = getIntent().getStringExtra(SocialConstants.PARAM_URL);
this.url = stringExtra;
if (!TextUtils.isEmpty(stringExtra)) {
this.webview.loadUrl(this.url);
return;
}
this.webview.loadUrl("https://kf.danyue.site/index.php?uid=123&userid=" + getUserId() + "&uName=" + AppManager.f().k().t_nickName + "&avatar=" + AppManager.f().k().headUrl);
}
@Override
protected void onDestroy() {
super.onDestroy();
WebView webView = this.webview;
if (webView != null) {
webView.clearCache(true);
this.webview.clearFormData();
this.webview.clearHistory();
this.webview.destroy();
}
this.webview = null;
}
@Override
public boolean onKeyDown(int i8, KeyEvent keyEvent) {
if (!this.webview.canGoBack() || i8 != 4) {
return super.onKeyDown(i8, keyEvent);
}
this.webview.goBack();
return true;
}
@Override
public void onRequestPermissionsResult(int i8, String[] strArr, int[] iArr) {
super.onRequestPermissionsResult(i8, strArr, iArr);
}
}