作者 潘达康

1、targetSDKVersion下调到29

2、加入返回键处理
3、更改外显名和icon
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project version="4">
  3 + <component name="VcsDirectoryMappings">
  4 + <mapping directory="$PROJECT_DIR$" vcs="Git" />
  5 + </component>
  6 +</project>
@@ -3,13 +3,13 @@ plugins { @@ -3,13 +3,13 @@ plugins {
3 } 3 }
4 4
5 android { 5 android {
6 - namespace 'com.qiwan.gameboxh5'  
7 - compileSdk 32 6 + namespace 'com.qiwan.gamebox'
  7 + compileSdk 29
8 8
9 defaultConfig { 9 defaultConfig {
10 applicationId "com.qiwan.gamebox" 10 applicationId "com.qiwan.gamebox"
11 minSdk 21 11 minSdk 21
12 - targetSdk 32 12 + targetSdk 29
13 versionCode 1 13 versionCode 1
14 versionName "1.0" 14 versionName "1.0"
15 15
@@ -4,8 +4,6 @@ @@ -4,8 +4,6 @@
4 <uses-permission android:name="android.permission.INTERNET"/> 4 <uses-permission android:name="android.permission.INTERNET"/>
5 <application 5 <application
6 android:allowBackup="true" 6 android:allowBackup="true"
7 - android:dataExtractionRules="@xml/data_extraction_rules"  
8 - android:fullBackupContent="@xml/backup_rules"  
9 android:icon="@mipmap/ic_launcher" 7 android:icon="@mipmap/ic_launcher"
10 android:label="@string/app_name" 8 android:label="@string/app_name"
11 android:supportsRtl="true" 9 android:supportsRtl="true"
@@ -11,8 +11,8 @@ import android.view.WindowManager; @@ -11,8 +11,8 @@ import android.view.WindowManager;
11 import android.webkit.WebSettings; 11 import android.webkit.WebSettings;
12 import android.webkit.WebView; 12 import android.webkit.WebView;
13 import android.widget.LinearLayout; 13 import android.widget.LinearLayout;
  14 +import android.widget.Toast;
14 15
15 -import com.qiwan.gameboxh5.R;  
16 import com.readystatesoftware.systembartint.SystemBarTintManager; 16 import com.readystatesoftware.systembartint.SystemBarTintManager;
17 17
18 public class MainActivity extends Activity { 18 public class MainActivity extends Activity {
@@ -51,38 +51,32 @@ public class MainActivity extends Activity { @@ -51,38 +51,32 @@ public class MainActivity extends Activity {
51 51
52 private void initView() { 52 private void initView() {
53 mLlRoot = findViewById(R.id.ll_root); 53 mLlRoot = findViewById(R.id.ll_root);
54 - mLlRoot.setPadding(0, mTintManager.getConfig().getStatusBarHeight(), 0, 0); 54 + mLlRoot.setPadding(0, mTintManager.getConfig().getStatusBarHeight(), 0, mTintManager.getConfig().getNavigationBarHeight()+20);
55 mWebView = findViewById(R.id.webview); 55 mWebView = findViewById(R.id.webview);
56 } 56 }
57 57
58 private void initWebView() { 58 private void initWebView() {
59 - mWebView.requestFocusFromTouch();// 设置可以获得焦点  
60 - mWebView.setBackgroundColor(Color.argb(0, 0, 0, 0));  
61 - mWebView.requestFocus(View.FOCUS_DOWN);// 获取焦点 或者使用 webView.requestFocus()同样的效果  
62 - mWebView.setEnabled(true); // 这里如果设置false, 则点击h5页面中的输入框时不能唤起软键盘  
63 - mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);  
64 - mWebView.setOnLongClickListener(new View.OnLongClickListener() {  
65 - @Override  
66 - public boolean onLongClick(View v) {  
67 - return true;  
68 - }  
69 - });  
70 -  
71 WebSettings webSettings = mWebView.getSettings(); 59 WebSettings webSettings = mWebView.getSettings();
72 - webSettings.setDefaultTextEncodingName("utf-8");  
73 webSettings.setJavaScriptEnabled(true); 60 webSettings.setJavaScriptEnabled(true);
74 - webSettings.setTextZoom(100);  
75 - webSettings.setDomStorageEnabled(true);  
76 - webSettings.setUseWideViewPort(true);  
77 - webSettings.setLoadWithOverviewMode(true);  
78 - webSettings.setSupportZoom(true);  
79 webSettings.setBuiltInZoomControls(true); 61 webSettings.setBuiltInZoomControls(true);
80 - // 解决部分机子不设置出现存储不了数据问题 62 + webSettings.setDisplayZoomControls(false);
81 webSettings.setCacheMode(WebSettings.LOAD_DEFAULT); 63 webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
82 - webSettings.setDatabaseEnabled(true);  
83 - String dir = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();  
84 - webSettings.setDatabasePath(dir);  
85 - webSettings.setGeolocationEnabled(true); 64 + webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
86 webSettings.setAllowFileAccess(true); 65 webSettings.setAllowFileAccess(true);
87 } 66 }
  67 +
  68 + private long mBackPressedTime = 0;
  69 + @Override
  70 + public void onBackPressed() {
  71 + if (mWebView != null && mWebView.canGoBack()) {
  72 + mWebView.goBack();
  73 + } else {
  74 + if(System.currentTimeMillis() - mBackPressedTime > 2000) {
  75 + Toast.makeText(this, "再按一次退出应用", Toast.LENGTH_SHORT).show();
  76 + mBackPressedTime = System.currentTimeMillis();
  77 + } else {
  78 + super.onBackPressed();
  79 + }
  80 + }
  81 + }
88 } 82 }
1 <resources> 1 <resources>
2 - <string name="app_name">游戏中心</string> 2 + <string name="app_name">7277</string>
3 </resources> 3 </resources>
1 -<?xml version="1.0" encoding="utf-8"?><!--  
2 - Sample backup rules file; uncomment and customize as necessary.  
3 - See https://developer.android.com/guide/topics/data/autobackup  
4 - for details.  
5 - Note: This file is ignored for devices older that API 31  
6 - See https://developer.android.com/about/versions/12/backup-restore  
7 --->  
8 -<full-backup-content>  
9 - <!--  
10 - <include domain="sharedpref" path="."/>  
11 - <exclude domain="sharedpref" path="device.xml"/>  
12 --->  
13 -</full-backup-content>  
1 -<?xml version="1.0" encoding="utf-8"?><!--  
2 - Sample data extraction rules file; uncomment and customize as necessary.  
3 - See https://developer.android.com/about/versions/12/backup-restore#xml-changes  
4 - for details.  
5 --->  
6 -<data-extraction-rules>  
7 - <cloud-backup>  
8 - <!-- TODO: Use <include> and <exclude> to control what is backed up.  
9 - <include .../>  
10 - <exclude .../>  
11 - -->  
12 - </cloud-backup>  
13 - <!--  
14 - <device-transfer>  
15 - <include .../>  
16 - <exclude .../>  
17 - </device-transfer>  
18 - -->  
19 -</data-extraction-rules>