APP启动页隐私弹窗实现说明

最近审核严禁,腾讯应用市场要求APP在启动页增加隐私政策和用户协议,用户从腾讯应用市场上下载APP,第一加载的时候弹窗,不然审核就不给过,样式大概如下

用户若点击不同意的时候,无法进入APP内部。下面把实现的代码贴上来

1、判断是否首次进入APP

/**
     * 是否是首次进入APP
     */
    public static boolean isFirstEnterApp() {
spHelper = new SharedPreferencesHelper(this, ConstantValue.userInfo);
        boolean isFirstEnterApp = (Boolean) spHelper.getSharedPreference(ConstantValue.isFirstEnterApp, true);
        return isFirstEnterApp;
    }
 
    /**
     * 保存首次进入APP状态
     */
    public static void saveFirstEnterApp() {
        spHelper.put(ConstantValue.isFirstEnterApp, false);
    }

 2、首次进入,显示隐私弹窗,若不是就判断是否申请权限

 if (isFirstEnterApp) {
            startDialog();
        }else {
            checkPermission();
        }

3、个人觉得隐私弹窗,主要难点在弹窗的实现,隐私政策和用户协议点击需要跳转到web页面。如果用多个textView拼接的话,会比较繁琐。这里用到了android自带的方法SpannableStringBuilder 来实现业务需求,代码如下

private void startDialog() {
        final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.show();
        alertDialog.setCancelable(false);
        Window window = alertDialog.getWindow();
        if (window != null) {
            window.setContentView(R.layout.dialog_initmate);
            window.setGravity(Gravity.CENTER);

            TextView tvContent = window.findViewById(R.id.tv_content);
            TextView tvCancel = window.findViewById(R.id.tv_cancel);
            TextView tvAgree = window.findViewById(R.id.tv_agree);
            String str = "    感谢您对本公司的支持!本公司非常重视您的个人信息和隐私保护。" +
                    "为了更好地保障您的个人权益,在您使用我们的产品前," +
                    "请务必审慎阅读《隐私政策》和《用户协议》内的所有条款," +
                    "尤其是:\n" +
                    " 1.我们对您的个人信息的收集/保存/使用/对外提供/保护等规则条款,以及您的用户权利等条款;\n" +
                    " 2. 约定我们的限制责任、免责条款;\n" +
                    " 3.其他以颜色或加粗进行标识的重要条款。\n" +
                    "如您对以上协议有任何疑问," +
                    "可通过人工客服或发邮件至sharetronicios@163.com与我们联系。您点击“同意并继续”的行为即表示您已阅读完毕并同意以上协议的全部内容。" +
                    "如您同意以上协议内容,请点击“同意”,开始使用我们的产品和服务!";

            SpannableStringBuilder ssb = new SpannableStringBuilder();
            ssb.append(str);
            final int start = str.indexOf("《");//第一个出现的位置
            ssb.setSpan(new ClickableSpan() {
                @Override
                public void onClick(@NonNull View widget) {
                    Toast.makeText(SplashScreenActivity.this, "《隐私政策》", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void updateDrawState(@NonNull TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setColor(getResources().getColor(R.color.gaoqing));
                    ds.setUnderlineText(false);
                }
            }, start, start + 6, 0);

            int end = str.lastIndexOf("《");
            ssb.setSpan(new ClickableSpan() {
                @Override
                public void onClick(@NonNull View widget) {
                    Toast.makeText(SplashScreenActivity.this, "《用户协议》", Toast.LENGTH_SHORT).show();
                }

                @Override
                public void updateDrawState(@NonNull TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setColor(getResources().getColor(R.color.gaoqing));
                    ds.setUnderlineText(false);
                }
            }, end, end + 6, 0);

            tvContent.setMovementMethod(LinkMovementMethod.getInstance());
            tvContent.setText(ssb, TextView.BufferType.SPANNABLE);


            tvCancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    spHelper.put(ConstantValue.isFirstEnterApp, true);
                    alertDialog.cancel();
                    finish();
                }
            });

            tvAgree.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    spHelper.put(ConstantValue.isFirstEnterApp, false);
                    checkPermission();
                    alertDialog.cancel();
                }
            });
        }

    }

4、弹窗布局文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="25dp"
            android:padding="@dimen/dp_5"
            android:text="用户协议与隐私政策"
            android:textColor="#282828"
            android:textSize="20sp"
            android:textStyle="bold" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:paddingTop="@dimen/dp_20"
            android:paddingBottom="@dimen/dp_20">

            <TextView
                android:id="@+id/tv_content"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:lineSpacingMultiplier="1.2"
                android:textColor="#282828"
                android:textSize="16sp" />
        </ScrollView>

        <View
            android:id="@+id/view_1"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#E7E7E7" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_cancel"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:padding="@dimen/dp_12"
                android:text="不同意"
                android:textColor="#282828"
                android:textStyle="bold" />

            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#E7E7E7" />

            <TextView
                android:id="@+id/tv_agree"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/view_1"
                android:layout_toRightOf="@+id/view_2"
                android:layout_weight="1"
                android:gravity="center"
                android:padding="@dimen/dp_12"
                android:text="同意"
                android:textColor="#282828"
                android:textStyle="bold" />
        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

 

参考于:

https://blog.csdn.net/yun382657988/article/details/103343880

  • 6
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值