作者 潘达康

1、targetSDKVersion下调到29

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