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

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

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

1、加个判断,其他应用市场不需要弹窗

private boolean showDialog = true;//腾讯应用市场显示隐私说明弹窗 设置为true
private static final String SP_IS_FIRST_ENTER_APP = "SP_IS_FIRST_ENTER_APP";

2、 判断是否首次进入APP

/**
     * 是否是首次进入APP
     */
    public static boolean isFirstEnterApp() {
        return SPUtils.getInstance().getBoolean(SP_IS_FIRST_ENTER_APP, true);
    }

    /**
     * 保存首次进入APP状态
     */
    public static void saveFirstEnterApp() {
        SPUtils.getInstance().put(SP_IS_FIRST_ENTER_APP, false);
    }

 3、首次进入,清楚登录信息,显示隐私弹窗,若不是,进入APP首页

/**
     * 首次进入App,清除登录信息,显示隐私说明
     */
    private void handleFirstEnterApp() {
        boolean firstEnterApp = LoginHelper.isFirstEnterApp();

        if (firstEnterApp) {
            LoginHelper.loginOut();
            LoginHelper.saveFirstEnterApp();
            startDialog();
        }else {
            checkIsShowScroll();
        }
    }

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

private void startDialog() {
        dialog = new AlertDialog.Builder(getContext()).create();
        dialog.show();
        //对话框弹出后点击或按返回键不消失;
        dialog.setCancelable(false);

        final Window window = dialog.getWindow();
        if (window != null) {
            window.setContentView(R.layout.dialog_intimate);
            window.setGravity(Gravity.CENTER);
            window.setWindowAnimations(com.jm.core.R.style.anim_panel_up_from_bottom);
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            //设置属性
            final WindowManager.LayoutParams params = window.getAttributes();
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
            params.dimAmount = 0.5f;
            window.setAttributes(params);
            TextView textView = window.findViewById(R.id.tv_1);
            TextView tvCancel= window.findViewById(R.id.tv_cancel);
            TextView tvAgree= window.findViewById(R.id.tv_agree);
            tvCancel.setOnClickListener(view ->startFinish());
            tvAgree.setOnClickListener(view -> enterApp());
            String str = "感谢您选择壁纸制作APP!我们非常重视您的个人信息和隐私保护。" +
                    "为了更好地保障您的个人权益,在您使用我们的产品前," +
                    "请务必审慎阅读《隐私政策》和《用户协议》内的所有条款," +
                    "尤其是:1.我们对您的个人信息的收集/保存/使用/对外提供/保护等规则条款,以及您的用户权利等条款; " +
                    "2. 约定我们的限制责任、免责条款; 3.其他以颜色或加粗进行标识的重要条款。如您对以上协议有任何疑问," +
                    "可通过人工客服或发邮件至2661630693@qq.com与我们联系。您点击\"同意并继续”的行为即表示您已阅读完毕并同意以上协议的全部内容。" +
                    "如您同意以上协议内容,请点击\"同意并继续”,开始使用我们的产品和服务!";
            textView.setText(str);

            SpannableStringBuilder ssb = new SpannableStringBuilder();
            ssb.append(str);
            final int start = str.indexOf("《");//第一个出现的位置
            ssb.setSpan(new ClickableSpan() {
                @Override
                public void onClick(View widget) {
                    getSupportDelegate().start(WebViewDelegate.create("隐私政策",
                            JConstants.URL_POLICY));
                    dialog.cancel();
                    SPUtils.getInstance().put(SP_IS_FIRST_ENTER_APP, true);
                }

                @Override

                public void updateDrawState(TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setColor(getProxyActivity().getResources().getColor(R.color.text_click_yellow));       //设置文件颜色
                    // 去掉下划线
                    ds.setUnderlineText(false);
                }

            }, start, start + 6, 0);

            final int end = str.lastIndexOf("《");//最后一个出现的位置

            ssb.setSpan(new ClickableSpan() {
                @Override
                public void onClick(View widget) {
                    getSupportDelegate().start(WebViewDelegate.create("用户协议",
                            JConstants.URL_AGREEMENT));
                    dialog.cancel();
                    SPUtils.getInstance().put(SP_IS_FIRST_ENTER_APP, true);
                }

                @Override

                public void updateDrawState(TextPaint ds) {
                    super.updateDrawState(ds);
                    ds.setColor(getProxyActivity().getResources().getColor(R.color.text_click_yellow));       //设置文件颜色
                    // 去掉下划线

                    ds.setUnderlineText(false);
                }

            }, end, end + 6, 0);

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

    private void enterApp() {//同意并继续,进入APP
        dialog.cancel();
        checkIsShowScroll();
    }

    private void startFinish() {//更改状态,finish APP
        SPUtils.getInstance().put(SP_IS_FIRST_ENTER_APP, true);
        dialog.cancel();
        _mActivity.finish();

    }

5、弹窗布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background_allow_solid"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp">

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

    <TextView
        android:id="@+id/tv_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_title"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="20dp"
        android:textSize="16sp"
        android:textColor="#282828"
        android:lineSpacingMultiplier="1.2"
        />
    <View
        android:id="@+id/view_1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#E7E7E7"
        android:layout_below="@+id/tv_1"
        android:layout_marginTop="20dp"/>
    <View
        android:id="@+id/view_2"
        android:layout_width="1dp"
        android:layout_height="50dp"
        android:background="#E7E7E7"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/view_1"/>
    <TextView
        android:id="@+id/tv_cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="不同意"
        android:textStyle="bold"
        android:textColor="#282828"
        android:layout_toLeftOf="@+id/view_2"
        android:layout_marginRight="50dp"
        android:layout_below="@+id/view_1"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        android:padding="8dp"/>

    <TextView
        android:id="@+id/tv_agree"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="同意并继续"
        android:textStyle="bold"
        android:textColor="@color/text_click_yellow"
        android:layout_toRightOf="@+id/view_2"
        android:layout_marginLeft="50dp"
        android:layout_below="@+id/view_1"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        android:padding="8dp"
        />
</RelativeLayout>

以上为全部实现代码。

  • 11
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值