Я работаю с Android Studio и Firebase.Все работало нормально, но какое-то время было невозможно принять нового пользователя в моем приложении.После подтверждения регистрации моя заявка возобновляет процесс регистрации с самого начала.Android Studio возвращает следующую ошибку, хотя с 27 мая 2019 года я ничего не менял:
E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
Я пытался обновить правила базы данных следующим образом:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=****} {
allow read, write;
}
}
}
Вот мойОсновная активность:
public class MainActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener,
OnFragmentInteractionListener, InternetCallbackListener{
FirebaseStorage storage = FirebaseStorage.getInstance();
private GoogleApiClient client;
protected GoogleHelper googleHelper;
private FirebaseAuth mAuth;
private GoogleSignInClient mGoogleSignInClient;
// [...]
@Override
protected void onCreate(Bundle savedInstanceState) {
if (!isTaskRoot()) {
finish();
return;
}
super.onCreate(savedInstanceState);
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("xxxxxxxxxxxx.apps.googleusercontent.com")
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
mAuth = FirebaseAuth.getInstance();
}
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, Statics.REQUEST_SIGN_IN);
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
// updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
}
// ...
}
});
}
// [...]
@Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
//updateUI(currentUser);
mAuth.signInAnonymously()
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInAnonymously:success");
FirebaseUser user = mAuth.getCurrentUser();
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInAnonymously:failure", task.getException());
Toast.makeText(MainActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
String uuid = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
dbHelper2.getUser(uuid, new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot document) {
thisUser = document.getData();
if (thisUser == null) {
// go to user profile activity to register
Intent i = new Intent(context, SubscriptionActivity.class);
//i.putExtra("userId", null);
context.startActivity(i);
}
}
});
// [...]
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onResult");
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == Statics.REQUEST_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e);
// ...
}
}
Спасибо за помощь.