|
|
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint; |
|
|
|
import android.app.ActivityManager; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Intent; |
|
|
|
import android.net.Uri; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Debug; |
|
|
|
import android.os.Handler; |
|
|
|
@ -16,6 +17,8 @@ import android.view.WindowManager; |
|
|
|
import android.webkit.ConsoleMessage; |
|
|
|
import android.webkit.JavascriptInterface; |
|
|
|
import android.webkit.WebChromeClient; |
|
|
|
import android.webkit.WebResourceRequest; |
|
|
|
import android.webkit.WebResourceResponse; |
|
|
|
import android.webkit.WebSettings; |
|
|
|
import android.webkit.WebView; |
|
|
|
import android.webkit.WebViewClient; |
|
|
|
@ -42,6 +45,8 @@ import com.shockman.sm.vendor.TargetVo; |
|
|
|
import org.greenrobot.eventbus.EventBus; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Scanner; |
|
|
|
@ -216,12 +221,30 @@ public class WebViewActivity extends BaseActivity { |
|
|
|
@Override |
|
|
|
protected void setListener() { |
|
|
|
binding.web.setWebViewClient(new WebViewClient() { |
|
|
|
@Override |
|
|
|
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { |
|
|
|
Uri uri = request.getUrl(); |
|
|
|
if (uri.toString().endsWith(".js")) { // 拦截 JS 文件请求
|
|
|
|
try { |
|
|
|
// 读取本地 JS 文件(以 assets 为例)
|
|
|
|
InputStream is = getAssets().open(uri.getPath().substring(1)); // 处理路径
|
|
|
|
// 设置正确的 MIME 类型
|
|
|
|
return new WebResourceResponse( |
|
|
|
"text/javascript", // MIME 类型
|
|
|
|
"UTF-8", // 编码
|
|
|
|
is |
|
|
|
); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
return super.shouldInterceptRequest(view, request); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public boolean shouldOverrideUrlLoading(WebView view, String url) { |
|
|
|
view.loadUrl(url); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
binding.web.setOnLongClickListener((View v) -> { |
|
|
|
|