gpt4 book ai didi

android - 无法让 Android 应用程序连接到 Firebase

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:20 24 4
gpt4 key购买 nike

所以我已经尝试了 3 次,但没有成功地制作一个将与 Firebase 通信的 Android 应用程序。就像 the tutorial 一样简单成功了,我忍不住想我或它(很可能是前者)缺少了一些东西。

我正在制作的示例应用程序只包含一个 TextView,它应该随着我在 https://dummy-firebase.firebaseio.com/ 的 Firebase 的任何更改而更新。 (因为我不能公开 Firebase,如果你愿意,可以粘贴你自己的 Firebase 的 URL 来测试代码)。这是 Firebase 上的内容的快照:

Firebase snapshot

这是我唯一的 Activity 的 onCreate:

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

Firebase f = new Firebase("https://dummy-firebase.firebaseio.com");
f.addValueEventListener(new ValueEventListener() {

@Override
public void onDataChange(DataSnapshot arg0) {
TextView textViewSample = (TextView) findViewById(R.id.sampleTextView);
textViewSample.setText(arg0.getValue(String.class));
}

@Override
public void onCancelled() {
// TODO Auto-generated method stub
}
});
}

这是唯一的 XML 文件,activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
android:id="@+id/sampleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

这是 list 的图片,因此您可以清楚地看到 INTERNET 权限:

enter image description here

现在,当我从浏览器更改 Firebase 上的数据时,我相信 TextView 中的数据应该会更新。这并没有发生,我在之前的 Firebase Android 项目尝试中尝试使用 EditTexts 和 Buttons 来放置数据,但没有成功。

提前感谢您抽出宝贵时间查看此内容。由于 Firebase 的设置似乎很简单(而且是针对 Javascript 版本的),我真的很困惑我做错了什么!

谢谢!!

最佳答案

您可以尝试使用最新的 SDK (v1.0.2) 看看它是否解决了问题?我们刚刚为 Android 的一些 SSL 限制添加了解决方法。

https://www.firebase.com/docs/downloads.html

关于android - 无法让 Android 应用程序连接到 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17572159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com