From 733f375821bc2658976306bb0170065074816923 Mon Sep 17 00:00:00 2001 From: pppscn <35696959@qq.com> Date: Sun, 6 Mar 2022 16:01:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=86=85=E5=B5=8C?= =?UTF-8?q?=20WebView=20=E6=89=93=E5=BC=80=E4=BD=BF=E7=94=A8=E5=B8=AE?= =?UTF-8?q?=E5=8A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 4 ++ .../idormy/sms/forwarder/HelpActivity.java | 60 +++++++++++++++++++ .../idormy/sms/forwarder/MainActivity.java | 7 ++- app/src/main/res/layout/activity_help.xml | 15 +++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/idormy/sms/forwarder/HelpActivity.java create mode 100644 app/src/main/res/layout/activity_help.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bbe24cf8..3d53445f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -117,6 +117,10 @@ android:name=".AppListActivity" android:exported="true" android:label="@string/app_list" /> + = Build.VERSION_CODES.O) { + webView.getSettings().setSafeBrowsingEnabled(false); + } + WebSettings webSetting = webView.getSettings(); + webSetting.setJavaScriptEnabled(true); + + webSetting.setBuiltInZoomControls(true); + webSetting.setDisplayZoomControls(false); + webSetting.setUseWideViewPort(true); + + webSetting.setBlockNetworkImage(false); + //缓存模式 + webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE); + webSetting.setDatabaseEnabled(true); + webSetting.setDomStorageEnabled(true); + webSetting.setAppCacheMaxSize(1024 * 1024 * 8); + webSetting.setAppCachePath(getFilesDir().getAbsolutePath()); + webSetting.setDatabasePath(getFilesDir().getAbsolutePath()); + webSetting.setAllowFileAccess(true); + webSetting.setAppCacheEnabled(true); + //webSetting.setTextZoom(100); + webSetting.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); + + //访问网页 + webView.loadUrl("https://gitee.com/pp/SmsForwarder/wikis/pages"); + //系统默认会通过手机浏览器打开网页,为了能够直接通过WebView显示网页,则必须设置 + webView.setWebViewClient(new WebViewClient() { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + //使用WebView加载显示url + view.loadUrl(url); + //返回true + return true; + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/idormy/sms/forwarder/MainActivity.java b/app/src/main/java/com/idormy/sms/forwarder/MainActivity.java index 6d0daea9..829fdbdf 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/MainActivity.java +++ b/app/src/main/java/com/idormy/sms/forwarder/MainActivity.java @@ -5,7 +5,6 @@ import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -59,6 +58,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +@SuppressWarnings("CommentedOutCode") public class MainActivity extends AppCompatActivity implements RefreshListView.IRefreshListener { private final String TAG = "MainActivity"; @@ -513,8 +513,9 @@ public class MainActivity extends AppCompatActivity implements RefreshListView.I intent = new Intent(this, AboutActivity.class); break; case R.id.to_help: - Uri uri = Uri.parse("https://gitee.com/pp/SmsForwarder/wikis/pages"); - intent = new Intent(Intent.ACTION_VIEW, uri); + //Uri uri = Uri.parse("https://gitee.com/pp/SmsForwarder/wikis/pages"); + //intent = new Intent(Intent.ACTION_VIEW, uri); + intent = new Intent(this, HelpActivity.class); break; default: return super.onOptionsItemSelected(item); diff --git a/app/src/main/res/layout/activity_help.xml b/app/src/main/res/layout/activity_help.xml new file mode 100644 index 00000000..a90ec662 --- /dev/null +++ b/app/src/main/res/layout/activity_help.xml @@ -0,0 +1,15 @@ + + + + + + + +