将图片上传到Firebase存储时应用崩溃-Kotlin

时间:2018-11-04 10:39:11

标签: android firebase kotlin firebase-storage

我从手机上的某个路径上传图片后,我的应用就会崩溃。用户也已成功验证到应用程序中,并且我已经导入了所有需要的SDK。 SDK的版本可能不正确,因为它不是最新版本。我观看了以下视频:https://youtu.be/86dkYGeXMaU

这是我的代码:

private fun UploadToFirebaseStorage(){

    if(PhotoUri == null) return

    Log.d("AuthMsgs", PhotoUri.toString())
    val filename = UUID.randomUUID().toString()

    val ref = 
    FirebaseStorage.getInstance().getReference("/images/$filename")

    ref.putFile(PhotoUri!!)
            .addOnSuccessListener {
                Log.d("AuthMsgs", "Photo Succes: " + it.metadata?.path)
            }


}

这是日志猫消息:

2018-11-04 11:29:39.040 20493-20493/com.David.DiveBuddy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.David.DiveBuddy, PID: 20493
java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.impl.MediaContentProvider from ProcessRecord{6385df5 20493:com.David.DiveBuddy/u0a340} (pid=20493, uid=10340) that is not exported from uid 10106
    at android.os.Parcel.readException(Parcel.java:1683)
    at android.os.Parcel.readException(Parcel.java:1636)
    at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4263)
    at android.app.ActivityThread.acquireProvider(ActivityThread.java:5475)
    at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2267)
    at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1515)
    at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1129)
    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:982)
    at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:835)
    at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:789)
    at com.google.firebase.storage.UploadTask.<init>(Unknown Source)
    at com.google.firebase.storage.StorageReference.putFile(Unknown Source)
    at com.David.DiveBuddy.LoginReg.UploadToFirebaseStorage(Login_reg.kt:212)
    at com.David.DiveBuddy.LoginReg.access$UploadToFirebaseStorage(Login_reg.kt:31)
    at com.David.DiveBuddy.LoginReg$registerUser$1.onComplete(Login_reg.kt:153)
    at com.google.android.gms.tasks.zzj.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6123)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

1 个答案:

答案 0 :(得分:0)

您只是忘记向您的GOOGLE_PHOTOS添加Manifest权限。

<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS"/>