Firebase RealtimeDatabase现在不工作?
现在,Firebase RealtimeDatabase“写入”正在工作。
这是Firebase示例代码。
FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef = database.getReference("message"); myRef.setValue("Hello, World!"); myRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { // This method is called once with the initial value and again // whenever data at this location is updated. String value = dataSnapshot.getValue(String.class); Log.d(TAG, "Value is: " + value); } @Override public void onCancelled(DatabaseError error) { // Failed to read value Log.w(TAG, "Failed to read value.", error.toException()); } });
ValueEventListener
的onDataChange
,但是我无法在Firebase控制台的实时数据库中find写入的数据。
另外,以前做的使用实时数据库的应用程序今天不行。
这是一个firebase的错误? 我现在能做什么?
PS:这是日志消息。
10-14 18:19:52.730 15916-15916/com.example.star_man.firebaserealtimedatabase V/FA: onActivityCreated 10-14 18:19:52.766 15916-15933/com.example.star_man.firebaserealtimedatabase I/art: Do partial code cache collection, code=61KB, data=47KB 10-14 18:19:52.766 15916-15933/com.example.star_man.firebaserealtimedatabase I/art: After code cache collection, code=61KB, data=47KB 10-14 18:19:52.766 15916-15933/com.example.star_man.firebaserealtimedatabase I/art: Increasing code cache capacity to 256KB 10-14 18:19:55.549 15916-15935/com.example.star_man.firebaserealtimedatabase I/art: Starting a blocking GC Instrumentation 10-14 18:19:56.858 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Using measurement service 10-14 18:19:56.860 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Connecting to remote service 10-14 18:19:56.872 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Activity resumed, time: 5619167420 10-14 18:19:56.876 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: ThreadedRenderer.create() translucent=false 10-14 18:19:56.884 15916-15916/com.example.star_man.firebaserealtimedatabase D/InputTransport: Input channel constructed: fd=80 10-14 18:19:56.886 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: setView = DecorView@304ed89[MainActivity] touchMode=true 10-14 18:19:56.905 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: dispatchAttachedToWindow 10-14 18:19:56.949 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,0][1440,2560] result=0x27 surface={isValid=true 525456977920} surfaceGenerationChanged=true 10-14 18:19:56.951 15916-15982/com.example.star_man.firebaserealtimedatabase D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1440x2560]-format:1 10-14 18:19:56.951 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: mHardwareRenderer.initialize() mSurface={isValid=true 525456977920} hwInitialized=true 10-14 18:19:56.981 15916-15970/com.example.star_man.firebaserealtimedatabase D/FA: Connected to remote service 10-14 18:19:56.981 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Processing queued up service tasks: 1 10-14 18:19:57.033 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1 10-14 18:19:57.033 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 10-14 18:19:57.035 15916-15916/com.example.star_man.firebaserealtimedatabase D/ViewRootImpl@b6baf53[MainActivity]: mHardwareRenderer.initializeIfNeeded()#2 mSurface={isValid=true 525456977920} 10-14 18:19:57.038 15916-15916/com.example.star_man.firebaserealtimedatabase V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@eceb89a nm : com.example.star_man.firebaserealtimedatabase ic=null 10-14 18:19:57.038 15916-15916/com.example.star_man.firebaserealtimedatabase I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 10-14 18:19:57.051 15916-15916/com.example.star_man.firebaserealtimedatabase D/InputTransport: Input channel constructed: fd=85 10-14 18:20:01.990 15916-15970/com.example.star_man.firebaserealtimedatabase V/FA: Inactivity, disconnecting from the service
尝试把OnComplete Listener,它被称为?
myRef.setValue("Hello, World!", new DatabaseReference.CompletionListener() { @Override public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) { if (databaseError != null) { Log.d("saving","Data could not be saved " + databaseError.getMessage()); } else { Log.d("saving","Data saved successfully."); } } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.e("saving","Saving failed: " + e.getMessage()); } });
原因是我们公司的防火墙。 但我不知道为什么onDataChange
callback函数被调用。 我认为应该调用onCancelled
callback函数。
无论如何,我修改了防火墙规则,现在运行良好。