【问题标题】:Android app not able to post data on firebaseAndroid 应用无法在 Firebase 上发布数据
【发布时间】:2015-08-31 20:19:14
【问题描述】:

我有一个需要在 firebase 上发布数据的 android 应用程序。当我用我的开发设备测试它时,它工作得很好。

当我在商店发布它并且我的朋友想在同一个 firebase 帐户上发布数据时 --- 它不起作用 --- 没有错误消息 -- 没有崩溃 --- 只是服务器上没有数据。

我需要询问 Firebase 的免费计划在这种情况下是否适用于 Google 商店上已发布的应用程序?或者我需要使用付费计划升级它。

我的代码如下:

Firebase ref = new Firebase(my_URL); 

String uniqueID = UUID.randomUUID().toString(); 
String date = Utility.getDateTime(); 

Firebase jobchild = ref.child(projectId); 
jobchild.setValue(uniqueID);

Firebase jimages = jobchild.child("ProjectId"); 
jimages.setValue(projectId); 

Firebase jdate = jobchild.child("LogDate"); 
jdate.setValue(date);

【问题讨论】:

  • 免费计划应该可以工作。可以分享一下相关代码吗?
  • 此处为 Firebase 工程师。 这与免费计划无关。但是,如果没有更多关于如何重现此问题的信息,将无法提供进一步的帮助。有什么方法可以创建stackoverflow.com/help/mcve
  • 感谢分享,不是按计划。向服务器添加数据的代码示例如下: Firebase ref = new Firebase(my_URL); String uniqueID = UUID.randomUUID().toString();字符串日期 = Utility.getDateTime(); Firebase jobchild = ref.child(projectId); jobchild.setValue(uniqueID); Firebase jimages = jobchild.child("ProjectId"); jimages.setValue(projectId); Firebase jdate = jobchild.child("LogDate"); jdate.setValue(date);
  • 这里仍然没有足够的信息来重现这个问题。请参阅提供的 Puf 链接。

标签: android firebase


【解决方案1】:

当我将您的代码放入 Android 应用程序时,它对我来说效果很好:

Firebase.setAndroidContext(this);

Firebase ref = new Firebase("https://stackoverflow.firebaseio.com/32319324");

// Ensure we start out with no data at this location
ref.removeValue();

// Monitor the location and output any data there to a text view
ref.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot snapshot) {
        TextView output = (TextView) Activity32319324.this.findViewById(R.id.content_32319324);
        for (DataSnapshot project: snapshot.getChildren()) {
            output.setText(
                "key="+project.getKey() + "\n" +
                "LogDate="+project.child("LogDate").getValue() + "\n" +
                "ProjectId="+project.child("ProjectId").getValue()+"\n\n"
            );
        }
    }
    @Override
    public void onCancelled(FirebaseError firebaseError) { }
});

// Write data to the location
String projectId = "42";
String uniqueID = UUID.randomUUID().toString();
String date = new Date().toString(); //Utility.getDateTime();

Firebase jobchild = ref.child(projectId);
jobchild.setValue(uniqueID);

Firebase jimages = jobchild.child("ProjectId");
jimages.setValue(projectId);

Firebase jdate = jobchild.child("LogDate");
jdate.setValue(date);

在此处查看应用程序:https://github.com/puf/firebase-stackoverflow-android(您的代码在 Activity32319324 中)

【讨论】:

    猜你喜欢
    • 2017-02-07
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 2017-01-13
    • 2017-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多