试图从Firebase实时数据库中获取String数组数据到我的android应用。没用

时间:2019-11-27 11:43:06

标签: java android firebase firebase-realtime-database

这是我的样本数据

FireBase data json

这是我的代码。在创建活动时,我已使用> addListenerForSingleValueEvent()从数据库获取天数。

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mainpage);

        FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference myRef = database.getReference("days");

        Log.d("MainTest", "Message : " + myRef);  //PRINTED

        myRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                Log.d("MainTest", "Message DataSnapshot : " + dataSnapshot); //NOT PRINTED

                ArrayList<String> days = new ArrayList<String>();
                for(DataSnapshot data : dataSnapshot.getChildren()){
                    days.add(data.getValue(String.class));
                }
                Log.d(this.getClass().getName(), "Value is: " + days.toString());
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
                Log.w(this.getClass().getName(), "Failed to read value.", databaseError.toException());
            }
        });

        signOut = findViewById(R.id.signOut);

        signOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mAuth = FirebaseAuth.getInstance();
                mUser = mAuth.getCurrentUser();
                mAuth.signOut();
                startActivity(new Intent(Mainpage.this, MainActivity.class));
            }
        });

        long time = 1000l;
        try {
            Thread.sleep(time);
        } catch(Exception e){
            Log.d("MainPage", "Exception : " + e);
        }
    }

活动开始时,不会从Firebase中获取数据。

编辑: 这是该应用程序的日志。

2019-11-27 18:27:41.558 19802-19802/? I/est.days: Not late-enabling -Xcheck:jni (already on)
2019-11-27 18:27:41.617 19802-19802/? E/est.days: Unknown bits set in runtime_flags: 0x8000
2019-11-27 18:27:41.618 19802-19802/? W/est.days: Unexpected CPU variant for X86 using defaults: x86
2019-11-27 18:27:41.939 19802-19853/com.test.days W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
2019-11-27 18:27:41.976 19802-19802/com.test.days I/FirebaseInitProvider: FirebaseApp initialization successful
2019-11-27 18:27:42.262 19802-19861/com.test.days W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied)
2019-11-27 18:27:42.250 19802-19802/com.test.days W/RenderThread: type=1400 audit(0.0:87): avc: denied { write } for name="property_service" dev="tmpfs" ino=8448 scontext=u:r:untrusted_app:s0:c133,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 app=com.test.days
2019-11-27 18:27:42.590 19802-19857/com.test.days W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
2019-11-27 18:27:42.907 19802-19802/com.test.days W/est.days: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2019-11-27 18:27:42.907 19802-19802/com.test.days W/est.days: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2019-11-27 18:27:43.072 19802-19857/com.test.days I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
2019-11-27 18:27:43.072 19802-19857/com.test.days I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
2019-11-27 18:27:43.193 19802-19860/com.test.days W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-11-27 18:27:43.217 19802-19860/com.test.days W/Gralloc3: mapper 3.x is not supported
2019-11-27 18:27:43.341 19802-19802/com.test.days W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@7dd8c74

我不确定应用程序中缺少什么。我已经加载了所有必需的依赖项,并使用了Firebase的电子邮件密码身份验证

0 个答案:

没有答案