gpt4 book ai didi

java - Firebase 身份验证要求更新 Google Play 服务

转载 作者:行者123 更新时间:2023-12-02 10:20:25 24 4
gpt4 key购买 nike

我想创建一个 EmailPassword 身份验证页面,因为它可以从下面的代码中推断出来:

package parsa.lop.sibeh;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private Button mLogin;
private EditText mEmail;
private EditText mPassword;
private GoogleApiClient mGoogleApiClient;

private FirebaseAuth.AuthStateListener mAuthListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
mLogin = findViewById(R.id.login);
mEmail = findViewById(R.id.email);
mPassword = findViewById(R.id.password);
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if(firebaseAuth.getCurrentUser() != null){
startActivity(new Intent(MainActivity.this, StartActivity.class));
}
}
};
}

@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}

public void loginButton(View view){

String email = mEmail.getText().toString();
String pass = mPassword.getText().toString();
mAuth.signInWithEmailAndPassword(email, pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(MainActivity.this, "Signed In", Toast.LENGTH_LONG).show();
}
}
});


}
}

我的应用程序build.gradle包含

implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-auth:16.1.0'

我的项目build.gradle包含

classpath 'com.google.gms:google-services:4.2.0' 

我已在 firebase 中创建了一个帐户,并在我的应用文件夹中下载了 google-services.json。所以我没有收到任何错误,除了当我通过 loginButton() 函数单击按钮时,我得到 Notification从模拟器更新 Google Play 服务

最佳答案

Firebase、Google map 等所有 Google 服务均适用于 Google Play 服务,如果您尚未更新这些服务,则这些服务中的任何一项都将在您的设备中运行,您需要更新它们并确保它们是最新的。

为了避免用户卡在该窗口,您可以添加一个检查来验证 Google Play 服务版本是否是最新的,如果不是,您可以重定向用户进行更新

final String appPackageName = "con.google.android.gms"; // package name of the app

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
//alarm to go and install Google Play Services
}else if(status == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED){
Toast.makeText(context,"please udpate your google play service",Toast.LENGTH_SHORT).show
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}

在您的 else 语句中,我们将重定向用户以将其安装在此位置

https://play.google.com/store/apps/details?id=com.google.android.gms

要从模拟器更新您的 Google Play 服务,请参阅此答案 updating Google play services in Emulator

关于java - Firebase 身份验证要求更新 Google Play 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54381075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com