最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android隱私協(xié)議提示彈窗的實(shí)現(xiàn)流程詳解

 更新時(shí)間:2023年01月30日 16:23:40   作者:kim5659  
這篇文章主要介紹了Android隱私協(xié)議提示彈窗的實(shí)現(xiàn)流程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧

android studio版本:2021.2.1

例程名稱:pravicydialog

功能:

1、啟動(dòng)app后彈窗隱私協(xié)議

2、屏蔽返回鍵

3、再次啟動(dòng)不再顯示隱私協(xié)議。

本例程的絕大部分代碼來自下面鏈接,因?yàn)楸救烁牧艘恍?,增加了一些功能,所以不有臉的算原?chuàng)了。

下面這個(gè)例子是“正宗”app隱私協(xié)議實(shí)現(xiàn)方法,而且協(xié)議內(nèi)容使用的是txt格式文件,據(jù)說如果使用html格式文件,各大平臺(tái)在審核的時(shí)候大概率無法通過,但協(xié)議內(nèi)容的還應(yīng)該有更詳細(xì)協(xié)議及說明的鏈接,我沒做,暫時(shí)還沒學(xué)會(huì),會(huì)了再修改一下。

Android 實(shí)現(xiàn)隱私政策提示彈窗

對(duì)原作者表示感謝!

直接上代碼:

MainActivity.java

/*
完成日期:2023年1月28日
功能:app協(xié)議頁
1、打開app彈出協(xié)議,禁止返回鍵取消顯示。
2、再次打開協(xié)議頁不再彈出。
 */
package com.example.pravicydialog;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
public class MainActivity extends AppCompatActivity {
    Dialog dialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PravicyCheck();
    }
    public void onClickAgree(View v)
    {
        dialog.dismiss();
        //下面將已閱讀標(biāo)志寫入文件,再次啟動(dòng)的時(shí)候判斷是否顯示。
        this.getSharedPreferences("file", Context.MODE_PRIVATE).edit()
                .putBoolean("AGREE", true)
                .apply();
    }
    public void onClickDisagree(View v)
    {
        System.exit(0);//退出軟件
    }
    public void showPrivacy(String privacyFileName){
        String str = initAssets(privacyFileName);
        final View inflate = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog_privacy_show, null);
        TextView tv_title = (TextView) inflate.findViewById(R.id.tv_title);
        tv_title.setText("隱私政策授權(quán)提示");
        TextView tv_content = (TextView) inflate.findViewById(R.id.tv_content);
        tv_content.setText(str);
        dialog = new AlertDialog
                .Builder(MainActivity.this)
                .setView(inflate)
                .show();
        // 通過WindowManager獲取
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        final WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width = dm.widthPixels*4/5;
        params.height = dm.heightPixels*1/2;
        dialog.setCancelable(false);//屏蔽返回鍵
        dialog.getWindow().setAttributes(params);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    }
    /**
     * 從assets下的txt文件中讀取數(shù)據(jù)
     */
    public String initAssets(String fileName) {
        String str = null;
        try {
            InputStream inputStream = getAssets().open(fileName);
            str = getString(inputStream);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return str;
    }
    public static String getString(InputStream inputStream) {
        InputStreamReader inputStreamReader = null;
        try {
            inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        BufferedReader reader = new BufferedReader(inputStreamReader);
        StringBuffer sb = new StringBuffer("");
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line);
                sb.append("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }
    public void PravicyCheck(){
        Boolean status =this.getSharedPreferences("file",Context.MODE_PRIVATE)
                .getBoolean("AGREE",false);
        if (status==true){
        }else{
            showPrivacy("privacy.txt");//放在assets目錄下的隱私政策文本文件
        }
    }
}

說明:

1、dialog.setCancelable(false);屏蔽返回鍵

2、將已閱讀標(biāo)志寫入文件,再次啟動(dòng)的時(shí)候判斷是否顯示。

preferences用法見,實(shí)現(xiàn)不同,原理一樣:分享一個(gè)SharedPreferences的工具類,方便保存數(shù)據(jù)

this.getSharedPreferences("file", Context.MODE_PRIVATE).edit()
                .putBoolean("AGREE", true)
                .apply();

3、判斷是否是第一次啟動(dòng)代碼塊:

 public void PravicyCheck(){
        //讀標(biāo)志
        Boolean status =this.getSharedPreferences("file",Context.MODE_PRIVATE)
                .getBoolean("AGREE",false);
        if (status==true){
        //如果status為true,不顯示對(duì)話框,直接進(jìn)主頁面。
        }else{
            //如果status不為true顯示對(duì)話框
            showPrivacy("privacy.txt");//放在assets目錄下的隱私政策文本文件
        }

activity_main.xml(這個(gè)是主頁面,可以什么都不放,我放了一個(gè)textview)

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">
    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="歡迎使用本app?。?
        android:textColor="#E91E63"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

dialog_privacy_show.xml(對(duì)話框)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/dialog_privacy_shape"
    android:orientation="vertical">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/ll_btn_bottom"
            android:layout_marginBottom="15dp"
            android:gravity="center"
            android:orientation="vertical">
            <TextView
                android:id="@+id/tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:text="隱私政策授權(quán)提示"
                android:textColor="#000000"
                android:textSize="18sp" />
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:fadingEdgeLength="50dp"
                android:requiresFadingEdge="horizontal">
                <TextView
                    android:id="@+id/tv_content"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="10dp"
                    android:singleLine="false"
                    android:text=""
                    android:textColor="#000000" />
            </ScrollView>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/ll_btn_bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:gravity="center"
            >
            <Button
                android:id="@+id/btn_agree"
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:layout_marginRight="15dp"
                android:text="同意"
                android:onClick="onClickAgree"
                android:textColor="#FF0006"
                android:background="@drawable/button_shape"/>
            <Button
                android:id="@+id/btn_disagree"
                android:layout_width="130dp"
                android:layout_marginBottom="2dp"
                android:layout_height="wrap_content"
                android:text="放棄使用"
                android:onClick="onClickDisagree"
                android:textColor="#000000"
                android:background="@drawable/button_shape"/>
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>

button_shape.xml(按鈕形狀等屬性)

<?xml version="1.0" encoding="utf-8" ?>
<!--相當(dāng)于做了一張圓角的圖片,然后給button作為背景圖片-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!--設(shè)置背景色-->
    <solid android:color="#F59E27" />
    <!--設(shè)置圓角-->
    <corners android:radius="105dip" />
    <padding
        android:bottom="2dp"
        android:left="33dp"
        android:right="33dp"
        android:top="2dp">
    </padding>
</shape>

dialog_privacy_shape.xml(對(duì)話框?qū)傩裕?/p>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- 填充色 -->
    <solid android:color="#ffffff" />
    <!-- 矩形圓角半徑 -->
    <corners android:radius="10dp" />
</shape>

各個(gè)文件位置如圖:

最后動(dòng)圖:

到此這篇關(guān)于Android隱私協(xié)議提示彈窗的實(shí)現(xiàn)流程詳解的文章就介紹到這了,更多相關(guān)Android提示彈窗內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

马山县| 内丘县| 民权县| 景泰县| 大冶市| 通许县| 理塘县| 炉霍县| 株洲市| 安福县| 霞浦县| 乐东| 龙井市| 颍上县| 建瓯市| 浮山县| 青田县| 阜新| 乌审旗| 习水县| 商水县| 沙河市| 万州区| 南阳市| 呼伦贝尔市| 谷城县| 会昌县| 易门县| 江西省| 丰都县| 上饶市| 威宁| 常州市| 合作市| 祥云县| 汾阳市| 于都县| 泽库县| 五河县| 荆门市| 冕宁县|