安卓版问题修复
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
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 {
|
||||
// 隐私协议内容
|
||||
final String privacyContext = "<html><body style='padding:16px;font-size:14px;line-height:1.8;'>" +
|
||||
"<h3>提示</h3>" +
|
||||
"欢迎使用本游戏!在使用前,请您充分阅读并理解:<br/>" +
|
||||
|
||||
"<b>我们收集的信息:</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 webView = new WebView(this);
|
||||
webView.loadData(privacyContext, "text/html", "utf-8");
|
||||
AlertDialog.Builder privacyDialog = new AlertDialog.Builder(this);
|
||||
privacyDialog.setCancelable(false);
|
||||
privacyDialog.setView(webView);
|
||||
privacyDialog.setTitle("提示");
|
||||
privacyDialog.setNegativeButton("拒绝", this);
|
||||
privacyDialog.setPositiveButton("同意", this);
|
||||
privacyDialog.create().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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user