简体   繁体   English

如何使条款和条件仅在我首次登录 Google 时出现?

[英]How do I make the terms and conditions appear only when I log in to Google for the first time?

I want to add terms and conditions when users use my app.我想在用户使用我的应用程序时添加条款和条件。 But I have to show terms and conditions only one time.但我必须只出示一次条款和条件。

I'm using firebase google login.我正在使用 firebase 谷歌登录。 But I have a problem when I show terms and conditions and how code remembers users accept terms and conditions and shows only one time.但是当我显示条款和条件以及代码如何记住用户接受条款和条件并且只显示一次时,我遇到了问题。

Here's a google login code.这是一个谷歌登录代码。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    //새로운 코드다 마

    signInButton = findViewById(R.id.signInButton);

    GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();

    googleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this,this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
            .build();

    auth = FirebaseAuth.getInstance(); //파이어 베이스 인증 객체 초기화
    signInButton.setOnClickListener(new View.OnClickListener() { // 구글 로그인 버튼을 클릭했을때 이곳을 수행
        @Override
        public void onClick(View view) {
            Intent intent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
            startActivityForResult(intent,REQ_SIGN_GOOGLE);




        }
    });


}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { // 구글 로그인 인증을 요청했을때 결과 값을 되돌려 받는 곳
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == REQ_SIGN_GOOGLE) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if(result.isSuccess() == true) { // true 생략 가능, 인증 결과가 성공적이면
            GoogleSignInAccount account = result.getSignInAccount(); //account 라는 데이터는 구글 로그인 정보를 담고 있습니다. - 닉네임,프로필사진uri,이메일 주소등
            resultLogin(account); // 로그인 결과 값 출력 수행하라는 메서드
        }
    }
}

private void resultLogin(GoogleSignInAccount account) {

    AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
    auth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if(task.isSuccessful()) { //로그인이 성공했으면

                Intent intent = new Intent(getApplicationContext(),Home.class);
                startActivity(intent);

            }
            else{
                Toast.makeText(LoginActivity.this,"로그인 실패",Toast.LENGTH_SHORT).show();

            }
        }
    });
}

@Override
public void onBackPressed() {
    long curTime=System.currentTimeMillis();
    long gapTime=curTime-backBtnTime;

    if(0<=gapTime && 2000>= gapTime){
        moveTaskToBack(true);
        finishAndRemoveTask();
        android.os.Process.killProcess(android.os.Process.myPid());

    }
    else {
        backBtnTime = curTime;
        Toast.makeText(this,"뒤로 버튼을 한 번 더 누르면 종료됩니다.",Toast.LENGTH_SHORT).show();
    }
}


@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}

Here is a code I want to show (terms and conditions)这是我要显示的代码(条款和条件)

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_terms);
    CheckBox checkBox=findViewById(R.id.checkbox);
    CheckBox checkBox2=findViewById(R.id.checkbox2);
    CheckBox checkBox3=findViewById(R.id.checkbox3);
    checkBox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(checkBox.isChecked()){
                checkBox2.setChecked(true);
                checkBox3.setChecked(true);

            }else {
                checkBox2.setChecked(false);
                checkBox3.setChecked(false);

            }
        }
    });

    checkBox2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           
            if(checkBox.isChecked()){
                checkBox.setChecked(false);
                
            }else if(checkBox2.isChecked()&&checkBox3.isChecked()){
                checkBox.setChecked(true);
            }
        }
    });

    checkBox3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(checkBox.isChecked()){
                checkBox.setChecked(false);
            }else if(checkBox2.isChecked()&&checkBox3.isChecked()){
                checkBox.setChecked(true);
            }
        }
    });


    Button btn_agr = findViewById(R.id.btn_agr1);
    btn_agr.setText(R.string.app_name);
    btn_agr.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(TermsActivity.this);
           
            builder.setTitle("서비스 이용약관 ");
            
            builder.setMessage(R.string.app_name); 
           
            builder.setNegativeButton("닫기",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            System.out.println(TAG + "이용약관 닫기");
                        }
                    });
           
            builder.show();
        }
    });


    Button btn_agr2 = findViewById(R.id.btn_agr2);
    btn_agr2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(TermsActivity.this);
           
            builder.setTitle("위치 정보 이용 약관 ");
            
            builder.setMessage(R.string.app_name); 
            builder.setNegativeButton("닫기",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            System.out.println(TAG + "이용약관 닫기");
                        }
                    });
    
            builder.show();
        }
    });

    Button btn_complete = findViewById(R.id.button_complete);
    btn_complete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


        }
    });


}

I tried my self - transmit variables when the user accept terms and conditions but when the user reopens the app user has to open it again Maybe there is a way to transmit certain variables to firebase and confirm it when the user clicks the login button??当用户接受条款和条件时,我尝试了我的自我传输变量,但是当用户重新打开应用程序时,用户必须再次打开它也许有一种方法可以将某些变量传输到 firebase 并在用户单击登录按钮时确认?

There is a way to transmit certain variables to firebase and confirm it when the user clicks the login button?有没有办法将某些变量传输到 firebase 并在用户单击登录按钮时确认?

The simplest solution would be to call AuthResult#getAdditionalUserInfo() method on the Task object, because it returns an object of type AdditionalUserInfo.最简单的解决方案是在任务 object 上调用AuthResult#getAdditionalUserInfo()方法,因为它返回 AdditionalUserInfo 类型的 object。 In this class, you can find a very useful method called isNewUser() , which can help you check if the user signs in for the first time.在这个 class 中,您可以找到一个非常有用的方法isNewUser() ,它可以帮助您检查用户是否是第一次登录。 In code should look like this:在代码中应该是这样的:

AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
auth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        if(task.isSuccessful()) { //로그인이 성공했으면

            boolean isNewUser = task.getResult().getAdditionalUserInfo().isNewUser();
            if (isNewUser) {
                //Display Terms & Conditions
            }

            Intent intent = new Intent(getApplicationContext(),Home.class);
            startActivity(intent);

        }
        else{
            Toast.makeText(LoginActivity.this,"로그인 실패",Toast.LENGTH_SHORT).show();

        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM