返回我下面Code for sending images using firebase爲什麼FirebaseAuth.getInstance()。getCurrentUser()採用的是Android
我已經配置了存儲火力URL,數據庫URL數據庫規則(真),SHA1放置谷歌的服務空值。 JSON在應用程序文件夾,但是當我調試的代碼是(用戶)顯示空值FirebaseUser user = firebaseAuth.getCurrentUser();
。我的代碼如下:
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import butterknife.Bind;
import butterknife.ButterKnife;
public class LoginActivity
extends AppCompatActivity
implements FirebaseAuth.AuthStateListener
{
@Bind(R.id.login_button)
Button loginButton;
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
}
@Override
public void onStart()
{
super.onStart();
firebaseAuth.addAuthStateListener(this);
verifyCurrentUserAndStartMainActivityIfLoggedIn();
}
@Override
public void onStop()
{
super.onStop();
firebaseAuth.removeAuthStateListener(this);
}
public void onLoginClicked(View view)
{
loginButton.setEnabled(false);
firebaseAuth.signInAnonymously();
}
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth)
{
verifyCurrentUserAndStartMainActivityIfLoggedIn();
}
private void verifyCurrentUserAndStartMainActivityIfLoggedIn()
{
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) //HERE I AM GETTING "user=null" ??
{
startActivity(new Intent(this, MainActivity.class));
Toast.makeText(this,"Login success",Toast.LENGTH_LONG).show();
finish();
}
else
{
loginButton.setEnabled(true);
}
}
}
成功後,現在登錄時(用戶!= NULL)下一個活動顯示下一個活動的樣本網址是
在火力// StorageReference storageRef = storage.getReferenceFromUrl("gs://funchat-ef3ed.appspot.com");
,我已經創造了新的存儲獲取網址是:
StorageReference storageRef = storage.getReferenceFromUrl("gs://fir-imagesending-1a8c1.appspot.com");
當我使用上面的URL應用程序崩潰。代碼如下:
public class MainActivity extends AppCompatActivity
{
static final int REQUEST_IMAGE_CAPTURE = 1;
FirebaseDatabase database = FirebaseDatabase.getInstance();
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
DatabaseReference databaseReference = database.getReference("messages");
FirebaseStorage storage = FirebaseStorage.getInstance();
// StorageReference storageRef = storage.getReferenceFromUrl("gs://funchat-ef3ed.appspot.com");
StorageReference storageRef = storage.getReferenceFromUrl("gs://fir-imagesending-1a8c1.appspot.com");
我無法找到我失蹤的地方?
是否啓用了在Firebase控制檯中的匿名登錄? – VizGhar
如果是的話,請使用'signInAnonymously()。addOnCompleteListener ...',這樣你就可以在回調中看到錯誤 – VizGhar
@VizGhar我已經啓用匿名登陸從firebase。 –