游戏软著渠道的用户协议和隐私协议方案(启动显示方案)

发布时间 2023-07-20 12:45:48作者: 威少小二orz

该方案为游戏启动时显示用户协议、隐私协议。

一般作为软著包上架的话使此方案。

方案描述:

Android启动的时候,首次启动时,先显示用户协议、点确定后再显示隐私协议,完成后再进入游戏。

进入游戏前,用户协议和隐私协议可以切换着点,进入游戏完成后,下次再启动游戏,则不会弹出协议确认界面。

1、AndroidManifest.xml的Application节点下增加如下activity。

    <activity android:name="com.mycaiyuan.shaiquwh.wxapi.MainActivity" android:theme="@style/UnityTransparentStatusBarTheme" android:exported="true" android:taskAffinity="com.mycaiyuan.shaiquwh" android:label="@string/app_name" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="true">

      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="android.notch_support" android:value="true" />
      <meta-data android:name="unityplayer.UnityActivity" android:theme="@style/UnityTransparentStatusBarTheme" android:value="true" />
    </activity>

2、创建MainActivity.java这个activity。

package com.gametest.game.wxapi;//wxapi之前的那段为包名

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;

import com.gametest.game.R;//包名和R包


public class MainActivity extends Activity {
    WebView webview;
    SharedPreferences shared;
    public boolean isYHXY = false;
    public boolean isYSZC = false;
    public static MainActivity mainActivity;
    public String url1 = "https://www.baidu.com";
    public String url2 = "https://www.baidu.com";

    private SharedPreferences.Editor editor;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        Log.d("xxxxxxx","xxxxxxx66666");
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT );//代码强制竖屏 //SCREEN_ORIENTATION_PORTRAIT

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE;
        getWindow().setAttributes(params);



        super.onCreate(savedInstanceState);

        shared= getSharedPreferences("is", MODE_PRIVATE);
        boolean hasAcceptPivacy=shared.getBoolean("hasAcceptPivacy", false);
        //如果已经同意过协议,直接进入游戏(一般第二次打开,就不需要再次弹出隐私协议了)
        if(hasAcceptPivacy){
            Intent intent1 =new Intent();
            intent1.setClass(MainActivity.this, WXEntryActivity.class);
            MainActivity.this.startActivity(intent1);
            finish();
        }
        else
        {

            setContentView(R.layout.activity_main2);
            webview = findViewById(R.id.web1);
            webview.loadUrl(url1);
            webview.setWebViewClient(new WebViewClient() {
                @Override

                public boolean shouldOverrideUrlLoading(WebView view, String url) {

                    view.loadUrl(url1);
                    return true;
                }

            });
            Button btn1 =findViewById(R.id.imgbtn_ysxy);
            TextView txt = findViewById(R.id.tvHand);
            findViewById(R.id.imgbtn_ysxy).setOnClickListener(new Button.OnClickListener()
            {
                public void onClick(View v)
                {

                    if (btn1.getText().toString().contains("隐私政策") == true)
                    {
                        btn1.setText("用户协议");
                        txt.setText("隐私政策");
                        webview.loadUrl(url2);
                        webview.setWebViewClient(new WebViewClient() {
                            @Override

                            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                                view.loadUrl(url2);
                                return true;
                            }

                        });

                    }
                    else if (btn1.getText().toString().contains("用户协议") == true)
                    {
                        btn1.setText("隐私政策");
                        txt.setText("用户协议");
                        webview.loadUrl(url1);
                        webview.setWebViewClient(new WebViewClient() {
                            @Override

                            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                                view.loadUrl(url1);
                                return true;
                            }

                        });

                    }
                }


            });



            //btn.setEnabled(false);

            //点击同意,进入游戏
            findViewById(R.id.imgbtn_start).setOnClickListener(new Button.OnClickListener()
            {
                public void onClick(View v)
                {
                    if (txt.getText().toString().contains("用户协议") == true)
                    {
                        isYHXY = true;
                    }
                    else if (txt.getText().toString().contains("隐私政策") == true)
                    {
                        isYSZC = true;
                    }

                    if(isYHXY == true && isYSZC == true)
                    {


                        Intent intent =new Intent();
                        editor = shared.edit();
                        //同意隐私协议,修改 已同意协议变量为true
                        editor.putBoolean("hasAcceptPivacy", true);
                        editor.commit();

                        intent.setClass(MainActivity.this, WXEntryActivity.class);
                        MainActivity.this.startActivity(intent);
                        finish();
                    }
                    else if (isYHXY == true && isYSZC == false)
                    {
                        btn1.setText("用户协议");
                        txt.setText("隐私政策");
                        webview.loadUrl(url2);
                        webview.setWebViewClient(new WebViewClient() {
                            @Override

                            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                                view.loadUrl(url2);
                                return true;
                            }

                        });
                        Button btn = findViewById(R.id.imgbtn_start);
                        btn.setEnabled(false);
                        btn.setText("同意");
                        Handler mHandler2 = new Handler(Looper.getMainLooper());
                        mHandler2.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                btn.setText("同意");
                                btn.setEnabled(true);
                            }
                        }, 3000);
                    }
                    else if (isYHXY == false && isYSZC == true)
                    {
                        btn1.setText("隐私政策");
                        txt.setText("用户协议");
                        webview.loadUrl(url1);
                        webview.setWebViewClient(new WebViewClient() {
                            @Override

                            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                                view.loadUrl(url1);
                                return true;
                            }

                        });
                        Button btn = findViewById(R.id.imgbtn_start);
                        btn.setEnabled(false);
                        btn.setText("同意");

                        Handler mHandler2 = new Handler(Looper.getMainLooper());
                        mHandler2.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                btn.setText("同意");
                                btn.setEnabled(true);
                            }
                        }, 3000);

                    }
                    else
                    {
                        webview.loadUrl(url1);
                        webview.setWebViewClient(new WebViewClient() {
                            @Override

                            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                                view.loadUrl(url1);
                                return true;
                            }

                        });
                    }

                }
            });
            //点击不同意,直接退出应用
            findViewById(R.id.imgbtn_end).setOnClickListener(new Button.OnClickListener()
            {
                public void onClick(View v)
                {
                    android.os.Process.killProcess(android.os.Process.myPid());
                    System.exit(0);
                }
            });


        }
    }


    @Override
    protected void onNewIntent(Intent intent) {
        // To support deep linking, we need to make sure that the client can get access to
        // the last sent intent. The clients access this through a JNI api that allows them
        // to get the intent set on launch. To update that after launch we have to manually
        // replace the intent with the one caught here.
        setIntent(intent);
        Log.d("xxxxxxx" , "555555");
    }
}

 

3、在res下的layout文件夹下创建activity_main2.xml这个layout。

用txt打开,内容改为如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <LinearLayout
            android:id="@+id/llBtns1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_alignParentTop="true"
            android:orientation="horizontal">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:layout_weight="1">

            <Button
                android:id="@+id/imgbtn_ysxy"
                android:layout_width="100dp"
                android:layout_height="40dp"
                android:text="隐私政策"
                android:textSize="16dp" />
        </LinearLayout>
        </LinearLayout>
        <TextView
            android:id="@+id/tvHand"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:textSize="20dp"
            android:gravity="center"
            android:text="用户协议"
            android:textColor="#000"/>

        <LinearLayout
            android:id="@+id/llBtns"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_alignParentBottom="true"
            android:orientation="horizontal">
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_weight="1">

                <Button
                    android:id="@+id/imgbtn_start"
                    android:layout_width="80dp"
                    android:layout_height="40dp"
                    android:text="同意"
                    android:textSize="16dp" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_weight="1">

                <Button
                    android:id="@+id/imgbtn_end"
                    android:layout_width="80dp"
                    android:layout_height="40dp"
                    android:text="不同意"
                    android:textSize="16dp" />
            </LinearLayout>
        </LinearLayout>

        <WebView
            android:id="@+id/web1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@id/llBtns"
            android:layout_below="@id/tvHand" />

    </RelativeLayout>


</FrameLayout>

4、这样就完成了启动协议页的创建。

其中MainActivity.java代码里的  WXEntryActivity.class  这个是你游戏的那个activity。