简体   繁体   中英

App crashes when uploading image to firebase storage - Kotlin

As soon as I upload an image from a path on the phone my app craches. The user is also successfully authenticated into the app and i've imported all the sdk's needed. It could be that the sdk's verision is not the right one, because it's not the newest verision. I followed this video: https://youtu.be/86dkYGeXMaU

this is my code:

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)
            }


}

heres the log cat message:

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)

您只是忘了将GOOGLE_PHOTOS权限添加到Manifest

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM