package com.example.durveshshah.feedback;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import com.firebase.client.Firebase;
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;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class Main4Activity extends AppCompatActivity {
private static final String TAG = "viewDatabase";
private DatabaseReference mRef;
private FirebaseDatabase mFirebaseDatabase;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private String UserId;
private ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
mListView = (ListView) findViewById(R.id.list);
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
mRef = mFirebaseDatabase.getReference();
final FirebaseUser user = mAuth.getCurrentUser();
UserId = user.getUid();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if(user!=null)
{
//User is signed in
Log.d(TAG,"onAuthStateChanged:signed_in:"+ user.getUid());
Log.d(TAG,"onAuthStateChanged:signed_in:"+ user.getEmail());
}
else
{
//User is signed out
Log.d(TAG,"onAuthStateChanged:signed_out");
}
}
};
mRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
//Log.i("phone",ds.getKey());
ArrayList<String> array = new ArrayList<>();
array.add(String.valueOf(ds.getValue()));
ArrayAdapter arrayAdapter = new ArrayAdapter(Main4Activity.this, android.R.layout.simple_list_item_1, array);
mListView.setAdapter(arrayAdapter);
}
}
@Override
public void onCancelled(DatabaseError databaseError)
{
Toast.makeText(Main4Activity.this,"Logged Out",Toast.LENGTH_SHORT).show();
}
});
}
}
我用signinwithemailandpassword內置火力機制在不同的活動和簽約後我希望查看特定用戶的內容查看從數據庫內容。相反,所有數據庫內容在我登錄的每個用戶中都可見。
請添加您的火力數據庫結構和要檢索的數據? –
這是唯一的結構 –
我想在這個活動 –