【发布时间】:2018-10-19 22:59:14
【问题描述】:
我正在使用 Sign-in with Google 方法在我的应用中登录用户。
问题 - 更新:
如果我卸载应用程序(在注销或未注销后)并重新安装应用程序,FirebaseAuth.getInstance().getCurrentUser() 将不为空。因此,用户可以访问该帐户。
我什至尝试通过清除应用数据,问题仍然存在。
在添加“FirebaseInstanceIdService”和“FirebaseMessagingService”服务之前,该应用运行良好。意思是卸载后自动退出。
Manifest.xml
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
<meta-data android:name="firebase_messaging_auto_init_enabled"
android:value="false" />
<meta-data android:name="firebase_analytics_collection_enabled"
android:value="false" />
....
<service
android:name=".services.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".services.MyFirebaseInstanceIDService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
....
MyFirebaseMessagingService.class
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MessagingService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.e(TAG, String.valueOf(remoteMessage));
}
}
MyFirebaseInstanceIDService.class
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "InstanceIdService";
@Override
public void onTokenRefresh() {
super.onTokenRefresh();
if (FirebaseAuth.getInstance().getCurrentUser() == null){
return;
}
String tokenId = FirebaseInstanceId.getInstance().getToken();
saveTokenIdToDatabase(tokenId);
}
}
signOutAccount 方法
private void signOutAccount(){
FirebaseAuth.getInstance.signOut();
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
finishAffinity();
}
【问题讨论】:
-
您在使用智能锁吗?如果是这样,即使是全新安装,firebase 也会自动登录您的 Google 帐户
-
试试这个
FirebaseAuth.AuthStateListener authListener = new FirebaseAuth.AuthStateListener() { @Override public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { FirebaseUser user = firebaseAuth.getCurrentUser(); if (user == null) { // user auth state is changed - user is null // launch login activity startActivity(new Intent(MainActivity.this, LoginActivity.class)); finish(); } } }; -
@GuilhermeFGL 没有智能锁。我什至没有改变我的测试设备。这是在我从事 FirebaseMessagingService 之后发生的
-
@D. 不,它不起作用。
-
请您删除这个
if (FirebaseAuth.getInstance().getCurrentUser() == null){ return; }
标签: android firebase firebase-authentication firebase-cloud-messaging