2024-11-21 12:48:35 +08:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
//这段代码用于在用户第一次启动应用时显示隐私政策界面,用户可以选择同意或拒绝隐私政策
|
|
|
|
|
|
//如果用户同意隐私政策则进入Unity Activity,否则退出应用
|
|
|
|
|
|
//请将AndroidManifest中的默认启动Activity设置为PrivacyActivity
|
|
|
|
|
|
//
|
|
|
|
|
|
public class PrivacyActivity extends Activity implements DialogInterface.OnClickListener {
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-21 13:43:03 +08:00
|
|
|
|
final String privacyContent = "欢迎使用本游戏,在使用前,清充分阅读并理解以下内容";
|
2024-11-21 12:48:35 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
|
|
if(GetPrivacyAccept()){
|
|
|
|
|
|
//如果用户已经同意隐私政策则直接进入Unity Activity
|
|
|
|
|
|
EnterUnityActivity();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ShowPrivacyDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ShowPrivacyDialog(){
|
|
|
|
|
|
WebView webView = new WebView(this);
|
|
|
|
|
|
webView.loadData(privacyContent, "text/html", "utf-8");
|
|
|
|
|
|
AlertDialog.Builder privacyDialog = new AlertDialog.Builder(this);
|
|
|
|
|
|
privacyDialog.setCancelable(false);
|
|
|
|
|
|
privacyDialog.setTitle("隐私政策");
|
|
|
|
|
|
privacyDialog.setView(webView);
|
|
|
|
|
|
privacyDialog.setPositiveButton("同意", this);
|
|
|
|
|
|
privacyDialog.setNegativeButton("拒绝", this);
|
|
|
|
|
|
privacyDialog.create().show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
switch (which) {
|
2024-11-21 13:43:03 +08:00
|
|
|
|
case AlertDialog.BUTTON_POSITIVE://点击同意按钮
|
|
|
|
|
|
SetPrivacyAccept(true);//设置已经同意隐私政策
|
2024-11-21 12:48:35 +08:00
|
|
|
|
EnterUnityActivity();//进入Unity Activity
|
|
|
|
|
|
break;
|
2024-11-21 13:43:03 +08:00
|
|
|
|
case AlertDialog.BUTTON_NEGATIVE://点击拒绝按钮
|
2024-11-21 12:48:35 +08:00
|
|
|
|
finish();
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void EnterUnityActivity() {
|
|
|
|
|
|
Intent unityAct = new Intent();
|
|
|
|
|
|
unityAct.setClassName(this, "com.unity3d.player.UnityPlayerActivity");
|
|
|
|
|
|
this.startActivity(unityAct);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetPrivacyAccept(boolean isAccept) {
|
|
|
|
|
|
//设置已经同意隐私政策
|
|
|
|
|
|
//这里可以使用SharedPreferences保存用户的选择
|
|
|
|
|
|
SharedPreferences.Editor prefs = this.getSharedPreferences("PlayerPrefs", MODE_PRIVATE).edit();
|
|
|
|
|
|
prefs.putBoolean("PrivacyAccept", isAccept);
|
|
|
|
|
|
prefs.apply();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean GetPrivacyAccept() {
|
|
|
|
|
|
//获取用户是否同意隐私政策
|
|
|
|
|
|
SharedPreferences prefs = this.getSharedPreferences("PlayerPrefs", MODE_PRIVATE);
|
|
|
|
|
|
return prefs.getBoolean("PrivacyAccept", false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|