[英]Device doesn't interact with Firebase, but emulator does
Right now I'm developing a Flutter app using Firebase's Realtime Database. 现在,我正在使用Firebase的实时数据库开发Flutter应用程序。 The problem I have is that my device can't seem to connect with Firebase at all. 我的问题是我的设备似乎根本无法与Firebase连接。 It can't upload any data to the DB nor read anything. 它无法将任何数据上传到数据库,也无法读取任何内容。
The thing got weird when I tried the exact same app and code on an Android emulator, as it worked as expected. 当我在Android模拟器上尝试完全相同的应用和代码时,事情变得很奇怪,因为它按预期工作。
Example code 范例程式码
This button below is supposed to upload something to the /carreras reference. 下面的这个按钮应该将某些内容上传到/ carreras参考。 Well, when I run an app with this code on an emulator, it works perfectly, but on my real device it doesn't. 好吧,当我在模拟器上运行带有此代码的应用程序时,它可以完美运行,但在我的真实设备上却不能。
new RaisedButton(
child: new Text("upload"),
onPressed: () {
var ref = FirebaseDatabase.instance.reference().child("carreras");
ref.set("some data").then((_) {
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text("data uploaded"),
));
});
},
)
My first guess is that it has to do with internet permissions but I've checked the app info on my device and emulator, and it says the app doesn't request anything. 我的第一个猜测是,这与Internet权限有关,但是我已经在设备和仿真器上检查了应用程序信息,并说该应用程序未请求任何内容。 I've searched through the web too and I don't seem to find anything related nor useful. 我也在网上搜索过,但似乎没有发现任何相关或有用的内容。
I just runned your code in real device. 我只是在真实设备中运行过您的代码。 And it works fine. 而且效果很好。 My guess is that maybe your real device's api level lower than 21. Are you running your app on a pre-Lollipop device? 我的猜测是,您实际设备的api级别可能低于21。您是否在预棒棒糖设备上运行应用程序? if it's 5.0 or higher, then my answer is wrong and the bug lies somewhere else. 如果它是5.0或更高,则我的答案是错误的,并且该错误位于其他地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.