简体   繁体   English

设备不与Firebase交互,但模拟器可以

[英]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.

相关问题 CORS + Android Webview,不适用于设备(​​但适用于模拟器) - CORS + Android Webview, doesn't work on device (but does on emulator) Android:图片不会在模拟器上加载到设备上 - Android: Image doesn't load on device while it does on emulator Firebase 从真实设备接收数据,但不从仿真器接收数据....为什么? - Firebase receives data from real device but doesn't from an emulator....why? 模拟器未在ddms的设备视图中显示 - emulator doesn't show in device view in ddms Firebase 在 Android Studio 模拟器上不起作用 - Firebase doesn't work on Android Studio Emulator 我的 flutter 应用程序在模拟器上完美地将文件上传到 firebase(启用了 vpn),但在我的 android 设备上没有这样做 - My flutter app uploads file to firebase perfectly on emulator(vpn enabled) but doesn't do so on my android device Firebase 不会在真实设备上检索数据,但在模拟器上可以正常工作 - Firebase won't retrieve data on real device, but works normally on emulator 我的设备上没有Firebase通知 - Firebase Notifications doesn't come on my device Android模拟器正确显示希伯来语资源,但设备没有 - Android emulator displays Hebrew resources correctly but device doesn't Android Studio Emulator 中的应用程序运行效果不如真实设备 - App in Android Studio Emulator doesn't work as good as on real device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM