处理离线Firestore文件上载

时间:2019-05-22 13:41:08

标签: android firebase google-cloud-firestore

当我上载没有Internet连接的文档时,我的加载器屏幕没有隐藏,因为firestore无法通过onSuccessListener或onFailureListener传递,而且我无法调用“ hideProgress()”方法。但是,如果我关闭该应用程序然后再次打开它,则新文档将正确添加到数据库中。我应该如何处理没有互联网连接?

那是我的代码:

   fun updateExercise(userId: String, documentId: String, exercise: DiaryRequest) {
    FirebaseFirestore.setLoggingEnabled(true)
    try {

        db.collection("utenti")
            .document(userId)
            .collection("diario")
            .document(documentId)
            .set(exercise, SetOptions.merge())
            .addOnSuccessListener {
                mView.onUploadCompleted()
            }
            .addOnFailureListener {
                mView.onUploadCompleted()
            }
    }catch (e: UnknownHostException){
        mView.onUploadCompleted()
    }
}

这是一条日志:

   2019-05-22 15:23:14.880 21568-21615/com.energym.app.energympalestre I/Firestore: (19.0.0) [WriteStream]: (44c5c29) Stream closed with status: 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:331)
    at io.grpc.internal.DnsNameResolver$1.run(DnsNameResolver.java:214)
    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:517)
    at io.grpc.internal.DnsNameResolver.resolveAll(DnsNameResolver.java:299)
    at io.grpc.internal.DnsNameResolver$1.run(DnsNameResolver.java:214) 
    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:517) 
    at io.grpc.internal.DnsNameResolver.resolveAll(DnsNameResolver.java:299) 
    at io.grpc.internal.DnsNameResolver$1.run(DnsNameResolver.java:214) 
    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) 
}.

0 个答案:

没有答案