build(android): 配置 Android 构建模板、包名与密钥库
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
package com.unity3d.player;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.webkit.WebView;
|
||||
|
||||
public class PrivacyActivity extends Activity implements DialogInterface.OnClickListener {
|
||||
// WebView 和 Dialog 引用,用于资源管理
|
||||
private WebView webView;
|
||||
private AlertDialog privacyDialog;
|
||||
|
||||
// 隐私协议内容
|
||||
final String privacyContext = "<html><body style='padding:16px;font-size:14px;line-height:1.8;'>" +
|
||||
"<h3>提示</h3>" +
|
||||
"欢迎使用本游戏!在使用前,请您充分阅读并理解:<br/>" +
|
||||
|
||||
"<b>Unity收集的信息:</b><br/>" +
|
||||
"• 设备信息:Android ID、IMEI、Mac地址、设备型号、系统版本<br/>" +
|
||||
"• 应用信息:应用安装列表<br/>" +
|
||||
"• 传感器信息:触屏、重力、加速度传感器(用于横竖屏适配)<br/><br/>" +
|
||||
|
||||
"<b>收集目的:</b><br/>" +
|
||||
"• 保障游戏正常运行、数据统计、和性能优化<br/><br/>" +
|
||||
|
||||
"<b>信息保护:</b><br/>" +
|
||||
"• 我们不会将您的个人信息出售给第三方,仅在法律要求或为提供服务所必需时才会共享。<br/><br/>" +
|
||||
|
||||
"<b>您的权利:</b><br/>" +
|
||||
"• 您有权拒绝我们收集信息,但可能导致游戏无法正常运行。<br/><br/>" +
|
||||
"</body></html>";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// 如果已经同意过隐私协议则直接进入Unity Activity
|
||||
if (GetPrivacyAccept()) {
|
||||
EnterUnityActivity();
|
||||
return;
|
||||
}
|
||||
// 弹出隐私协议对话框
|
||||
ShowPrivacyDialog();
|
||||
}
|
||||
|
||||
// 显示隐私协议对话框
|
||||
private void ShowPrivacyDialog() {
|
||||
webView = new WebView(this);
|
||||
webView.loadData(privacyContext, "text/html", "utf-8");
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setCancelable(false);
|
||||
builder.setView(webView);
|
||||
builder.setTitle("隐私政策");
|
||||
builder.setNegativeButton("拒绝", this);
|
||||
builder.setPositiveButton("同意", this);
|
||||
privacyDialog = builder.create();
|
||||
privacyDialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
switch (i) {
|
||||
case AlertDialog.BUTTON_POSITIVE:// 点击同意按钮
|
||||
SetPrivacyAccept(true);
|
||||
EnterUnityActivity(); // 启动Unity Activity
|
||||
break;
|
||||
case AlertDialog.BUTTON_NEGATIVE:// 点击拒绝按钮,直接退出App
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 启动Unity Activity
|
||||
private void EnterUnityActivity() {
|
||||
Intent unityAct = new Intent();
|
||||
unityAct.setClassName(this, "com.unity3d.player.UnityPlayerActivity");
|
||||
this.startActivity(unityAct);
|
||||
// 启动Unity Activity后,finish掉PrivacyActivity,避免退出时返回到这里
|
||||
this.finish();
|
||||
}
|
||||
|
||||
// 本地存储保存同意隐私协议状态
|
||||
private void SetPrivacyAccept(boolean accepted) {
|
||||
SharedPreferences.Editor prefs = this.getSharedPreferences("PlayerPrefs", MODE_PRIVATE).edit();
|
||||
prefs.putBoolean("PrivacyAcceptedKey", accepted);
|
||||
prefs.apply();
|
||||
}
|
||||
|
||||
// 获取是否已经同意过
|
||||
private boolean GetPrivacyAccept() {
|
||||
SharedPreferences prefs = this.getSharedPreferences("PlayerPrefs", MODE_PRIVATE);
|
||||
return prefs.getBoolean("PrivacyAcceptedKey", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
// 暂停 WebView 以节省资源
|
||||
if (webView != null) {
|
||||
webView.onPause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// 恢复 WebView
|
||||
if (webView != null) {
|
||||
webView.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// 关闭对话框
|
||||
if (privacyDialog != null && privacyDialog.isShowing()) {
|
||||
privacyDialog.dismiss();
|
||||
privacyDialog = null;
|
||||
}
|
||||
// 显式销毁 WebView 释放资源,防止内存泄漏
|
||||
if (webView != null) {
|
||||
webView.onPause();
|
||||
webView.removeAllViews();
|
||||
webView.destroy();
|
||||
webView = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user