PrivacyActivity.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.unity3d.player;
  2. import android.app.Activity;
  3. import android.app.AlertDialog;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.content.SharedPreferences;
  7. import android.os.Bundle;
  8. import android.webkit.WebView;
  9. public class PrivacyActivity extends Activity implements DialogInterface.OnClickListener {
  10. // 隐私协议内容
  11. final String privacyContext =
  12. "欢迎使用本游戏,在使用本游戏前,请您充分阅读并理解 <a href=\"https://docs.qq.com/doc/DQkJ6UHdkVWhneUV5\">《隐私政策》</a>各条;\n" +
  13. "1.保护用户隐私是本游戏的一项基本政策,本游戏不会泄露您的个人信息;\n" +
  14. "2.我们会根据您使用的具体功能需要,收集必要的用户信息(如申请设备信息,存储等相关权限);\n" +
  15. "3.在您同意App隐私政策后,我们将进行集成SDK的初始化工作,会收集您的android_id、Mac地址、IMEI和应用安装列表,以保障App正常数据统计和安全风控;\n" +
  16. "4.为了方便您的查阅,您可以通过“设置”重新查看该协议;\n" +
  17. "5.您可以阅读完整版的隐私保护政策了解我们申请使用相关权限的情况,以及对您个人隐私的保护措施。";
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. // 如果已经同意过隐私协议则直接进入Unity Activity
  22. if (GetPrivacyAccept()){
  23. EnterUnityActivity();
  24. return;
  25. }
  26. // 弹出隐私协议对话框
  27. ShowPrivacyDialog();
  28. }
  29. // 显示隐私协议对话框
  30. private void ShowPrivacyDialog(){
  31. WebView webView = new WebView(this);
  32. webView.loadData(privacyContext, "text/html", "utf-8");
  33. AlertDialog.Builder privacyDialog = new AlertDialog.Builder(this);
  34. privacyDialog.setCancelable(false);
  35. privacyDialog.setView(webView);
  36. privacyDialog.setTitle("提示");
  37. privacyDialog.setNegativeButton("拒绝",this);
  38. privacyDialog.setPositiveButton("同意",this);
  39. privacyDialog.create().show();
  40. }
  41. @Override
  42. public void onClick(DialogInterface dialogInterface, int i) {
  43. switch (i){
  44. case AlertDialog.BUTTON_POSITIVE://点击同意按钮
  45. SetPrivacyAccept(true);
  46. EnterUnityActivity(); //启动Unity Activity
  47. break;
  48. case AlertDialog.BUTTON_NEGATIVE://点击拒绝按钮,直接退出App
  49. finish();
  50. break;
  51. }
  52. }
  53. // 启动Unity Activity
  54. private void EnterUnityActivity(){
  55. Intent unityAct = new Intent();
  56. unityAct.setClassName(this, "com.taptap.xy.yousanjie.MainActivity");
  57. this.startActivity(unityAct);
  58. }
  59. // 本地存储保存同意隐私协议状态
  60. private void SetPrivacyAccept(boolean accepted){
  61. SharedPreferences.Editor prefs = this.getSharedPreferences("PlayerPrefs", MODE_PRIVATE).edit();
  62. prefs.putBoolean("PrivacyAcceptedKey", accepted);
  63. prefs.apply();
  64. }
  65. // 获取是否已经同意过
  66. private boolean GetPrivacyAccept(){
  67. SharedPreferences prefs = this.getSharedPreferences("PlayerPrefs", MODE_PRIVATE);
  68. return prefs.getBoolean("PrivacyAcceptedKey", false);
  69. }
  70. }