当前位置: 首页 > 知识库问答 >
问题:

Firebase存储无internet连接回调[关闭]

宋昊然
2023-03-14

当应用程序开始时,我正在从Firebase存储加载一些数据,我正在设置'on成功监听器'和'onFailureListener'以在加载完成时隐藏进度条。问题是:当我离线尝试应用程序时,我根本没有收到回调。我尝试了onCompleteListener,但它也没有被调用它在控制台中给我提供了以下消息:

W/ManagedChannelImpl: [{0}] Failed to resolve name. status={1}
W/Firestore: (21.4.1) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: Status{code=UNAVAILABLE, description=Unable to resolve host firestore.googleapis.com, cause=java.lang.RuntimeException: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname
        at io.grpc.internal.DnsNameResolver.resolveAll(DnsNameResolver.java:420)
        at io.grpc.internal.DnsNameResolver$Resolve.resolveInternal(DnsNameResolver.java:256)
        at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:213)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.net.UnknownHostException: Unable to resolve host "firestore.googleapis.com": No address associated with hostname
        at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:157)
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:105)
        at java.net.InetAddress.getAllByName(InetAddress.java:1154)
        at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:640)
        at io.grpc.internal.DnsNameResolver.resolveAll(DnsNameResolver.java:388)
        at io.grpc.internal.DnsNameResolver$Resolve.resolveInternal(DnsNameResolver.java:256) 
        at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:213) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
     Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
        at libcore.io.Linux.android_getaddrinfo(Native Method)
        at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:172)
        at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:137)
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:105) 
        at java.net.InetAddress.getAllByName(InetAddress.java:1154) 
        at io.grpc.internal.DnsNameResolver$JdkAddressResolver.resolveAddress(DnsNameResolver.java:640) 
        at io.grpc.internal.DnsNameResolver.resolveAll(DnsNameResolver.java:388) 
        at io.grpc.internal.DnsNameResolver$Resolve.resolveInternal(DnsNameResolver.java:256) 
        at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:213) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
    }
    This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

然后,只要应用程序正在运行,就会显示以下消息:

W/ExponenentialBackoff: network unavailable, sleeping.
W/ExponenentialBackoff: network unavailable, sleeping.
W/ExponenentialBackoff: network unavailable, sleeping.
W/ExponenentialBackoff: network unavailable, sleeping.
W/ExponenentialBackoff: network unavailable, sleeping.
W/ExponenentialBackoff: network unavailable, sleeping.
W/ExponenentialBackoff: network unavailable, sleeping.
.
.
.

等待了这么长时间后,它最终给出一个错误并触发“失败侦听器”:

E/StorageException: StorageException has occurred.
    The operation retry limit has been exceeded.
     Code: -13030 HttpResult: -2
E/StorageException: Could not open resulting stream.
    java.io.IOException: Could not open resulting stream.
        at com.google.firebase.storage.StreamDownloadTask.createDownloadStream(com.google.firebase:firebase-storage@@19.1.1:145)
        at com.google.firebase.storage.StreamDownloadTask.access$000(com.google.firebase:firebase-storage@@19.1.1:36)
        at com.google.firebase.storage.StreamDownloadTask$1.call(com.google.firebase:firebase-storage@@19.1.1:167)
        at com.google.firebase.storage.StreamDownloadTask$1.call(com.google.firebase:firebase-storage@@19.1.1:164)
        at com.google.firebase.storage.StreamDownloadTask$StreamProgressWrapper.ensureStream(com.google.firebase:firebase-storage@@19.1.1:325)
        at com.google.firebase.storage.StreamDownloadTask$StreamProgressWrapper.access$100(com.google.firebase:firebase-storage@@19.1.1:262)
        at com.google.firebase.storage.StreamDownloadTask.run(com.google.firebase:firebase-storage@@19.1.1:175)
        at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072)
        at com.google.firebase.storage.StorageTask$$Lambda$12.run(Unknown Source:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
E/StorageException: StorageException has occurred.
    The operation retry limit has been exceeded.
     Code: -13030 HttpResult: -2
E/StorageException: Could not open resulting stream.
    java.io.IOException: Could not open resulting stream.
        at com.google.firebase.storage.StreamDownloadTask.createDownloadStream(com.google.firebase:firebase-storage@@19.1.1:145)
        at com.google.firebase.storage.StreamDownloadTask.access$000(com.google.firebase:firebase-storage@@19.1.1:36)
        at com.google.firebase.storage.StreamDownloadTask$1.call(com.google.firebase:firebase-storage@@19.1.1:167)
        at com.google.firebase.storage.StreamDownloadTask$1.call(com.google.firebase:firebase-storage@@19.1.1:164)
        at com.google.firebase.storage.StreamDownloadTask$StreamProgressWrapper.ensureStream(com.google.firebase:firebase-storage@@19.1.1:325)
        at com.google.firebase.storage.StreamDownloadTask$StreamProgressWrapper.access$100(com.google.firebase:firebase-storage@@19.1.1:262)
        at com.google.firebase.storage.StreamDownloadTask.run(com.google.firebase:firebase-storage@@19.1.1:175)
        at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072)
        at com.google.firebase.storage.StorageTask$$Lambda$12.run(Unknown Source:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
W/Warning: Maybe internet or authentication issues
    com.google.firebase.storage.StorageException: The operation retry limit has been exceeded.
        at com.google.firebase.storage.StreamDownloadTask.snapStateImpl(com.google.firebase:firebase-storage@@19.1.1:229)
        at com.google.firebase.storage.StreamDownloadTask.snapStateImpl(com.google.firebase:firebase-storage@@19.1.1:35)
        at com.google.firebase.storage.StorageTask.snapState(com.google.firebase:firebase-storage@@19.1.1:343)
        at com.google.firebase.storage.TaskListenerImpl.onInternalStateChanged(com.google.firebase:firebase-storage@@19.1.1:85)
        at com.google.firebase.storage.StorageTask.tryChangeState(com.google.firebase:firebase-storage@@19.1.1:390)
        at com.google.firebase.storage.StorageTask.tryChangeState(com.google.firebase:firebase-storage@@19.1.1:426)
        at com.google.firebase.storage.StreamDownloadTask.run(com.google.firebase:firebase-storage@@19.1.1:201)
        at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072)
        at com.google.firebase.storage.StorageTask$$Lambda$12.run(Unknown Source:2)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.io.IOException: Could not open resulting stream.
        at com.google.firebase.storage.StreamDownloadTask.createDownloadStream(com.google.firebase:firebase-storage@@19.1.1:145)
        at com.google.firebase.storage.StreamDownloadTask.access$000(com.google.firebase:firebase-storage@@19.1.1:36)
        at com.google.firebase.storage.StreamDownloadTask$1.call(com.google.firebase:firebase-storage@@19.1.1:167)
        at com.google.firebase.storage.StreamDownloadTask$1.call(com.google.firebase:firebase-storage@@19.1.1:164)
        at com.google.firebase.storage.StreamDownloadTask$StreamProgressWrapper.ensureStream(com.google.firebase:firebase-storage@@19.1.1:325)
        at com.google.firebase.storage.StreamDownloadTask$StreamProgressWrapper.access$100(com.google.firebase:firebase-storage@@19.1.1:262)
        at com.google.firebase.storage.StreamDownloadTask.run(com.google.firebase:firebase-storage@@19.1.1:175)
        at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@19.1.1:1072) 
        at com.google.firebase.storage.StorageTask$$Lambda$12.run(Unknown Source:2) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 

当这种情况发生时,我希望尽快收到回电。

共有1个答案

楚硕
2023-03-14

您确实收到了一个失败回调,但原因是错误\u重试\u限制\u超过了。FirebaseStorage似乎不检查是否已连接internet,但仍尝试启动任务。你不想在自己开始上传/下载任务之前检查一下是否有互联网连接吗?

    public static boolean isOnline() {
        Runtime runtime = Runtime.getRuntime();
        try {
            Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
            int     exitValue = ipProcess.waitFor();
            return (exitValue == 0);
        }
        catch (IOException | InterruptedException e) { e.printStackTrace(); }

        return false;
    }

编辑:

通常,您希望在重新加载数据时保持此功能。想象一下这样一种情况:用户有一个internet连接,但速度有点慢或不一致,FirebaseStorage将通过第二次或第三次尝试启动下载任务。

只有一个选项会影响Firebase storage重试机制,此处描述:如何缩短网络错误时Firebase storage下载重试时间
或者您可以按照我的建议,首先检查用户是否已连接internet,然后才开始任务:

void yourMethod(...) {
   if (!isOnline) {
       //hiding progress bar
       //and fallback, maybe Toast to inform the user about the issue with internet connection
       return;
   }
   // start your download task
}
 类似资料:
  • 我有一个Go语言的后端,想知道如何连接到Firebase存储来创建/删除桶和添加/删除文件。我可以使用管理sdk。我在谷歌云存储的Go语言中找到了客户端存储库。我可以用那个吗?Firebase存储和谷歌云存储有什么区别?

  • 我在用admob做广告。如果我在打开应用程序之前连接到互联网,广告加载是正确的,但如果我先启动应用程序而没有连接到互联网,在应用程序启动后,如果我连接到互联网,则没有回调到onadload,在加载广告时失败。 我的布局概述: Java代码: 这很奇怪,因为在应用程序运行后连接到internet时没有对onAdLoaded的回调。adView可见性是否导致问题?我相信可见性不是一个问题,因为最初ad

  • 问题内容: 我正在尝试在github仓库上连接詹金斯。 当我指定Repo URL jenkins时,返回以下错误消息: 无法连接到存储库:命令“ git ls-remote -h git@github.com:adolfosrs / jenkins-test.git HEAD”返回状态码128:stdout:stderr:主机密钥验证失败。致命:无法从远程存储库读取。请确保您具有正确的访问权限,并

  • 我正在尝试使用Android studio提供的工具将我的Android应用程序连接到firebase,但我面临着很多麻烦。 我已经尝试更新依赖到最新的最新的谷歌服务,但错误仍然存在,显示的错误是无法解析Android应用模块的Gradle配置。解决分级生成问题和/或重新同步。 分级/应用程序a

  • 问题内容: 如何使用Javascript检查互联网连接?这样,我可以有一些条件说“在生产过程中使用Google缓存的JQuery版本,在开发过程中使用该版本或本地版本,具体取决于Internet连接”。 问题答案: 针对您的特定情况的最佳选择可能是: 在您的结束标记之前: 鉴于您的问题集中在jQuery上,这可能是最简单的方法。 如果您想要一个更强大的解决方案,可以尝试: 阅读有关W3C在脱机We

  • 我显然遗漏了一些东西。我正在制作一个简单的应用程序,其中包含并面临以下错误: 我的代码: 应用程序: pom.xml 控制器: 人事服务: 个人服务: PersonRepository(此存储库不能自动连接): 已经在网上搜索了。我什么都没找到。有什么想法吗?