Search code examples
androidfirebasekotlincamerastorage

Kotlin: Camera takes photos only on emulator (Android 8) and incorrectly displays links to photos in Realtime Database from Storage


I'm writing an application in the form of instagram (I study lessons from YouTube, they create it on Android 8, I'm trying to do the same on Android 10), I've only known Kotlin for a couple of weeks. Already implemented a lot. But it is with firebase that problems arise. Two questions:

  1. Register a user in the application and save his text data in firebase - I can do it from any device. Through the emulator on Android 8 - I can take a picture and everything works as it should, even the link to change the profile photo is displayed correctly. There is also a ShareActivity file where the user can share a photo on the "wall" and the problem is that photos appear in storage in google firebase, and in the realtime database the link to this photo is written as "com.google.firebase.storage.UploadTask $TaskSnapshot@46529a6", but should be written as a link "https://firebasestorage.googleapis.com/v0/b/instapirate...", while the profile photo is displayed correctly, namely posts - no, photos are simply not visible . How to fix this bug? I attach a photo from the emulator and the database: posts from emulator realtime database realtime database2
  2. And one more problem, which is that on Android 8 in the Instagram emulator I was asked for permission to the camera, I allowed it and the camera works, takes pictures and everything happens fine. And in android 10, permission to the camera is not requested and, therefore, the camera opens, takes pictures, but cannot save the photos (reopens when I click on the "save" button). A few times if I poke the buttons quickly - sometimes it helps to save the photo, but this happens in one case in a million. Not the fact that this is due to the resolution of the camera. I attach the code below: AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.instapirate">


    <uses-feature android:name="android.hardware.camera"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.INSTApirate" >

        <activity
            android:name=".activities.MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".activities.SearchActivity" />
        <activity android:name=".activities.ShareActivity" />
        <activity android:name=".activities.LikesActivity" />
        <activity android:name=".activities.ProfileActivity" />
        <activity
            android:name=".activities.EditProfileActivity"
            android:exported="true" />
        <activity
            android:name=".activities.LoginActivity"
            android:windowSoftInputMode="stateVisible|adjustResize" >
        </activity>
        <activity
            android:name=".activities.RegisterActivity"
            android:windowSoftInputMode="stateVisible|adjustResize" >
        </activity>
        <activity android:name=".activities.ProfileSettingsActivity" />
        <activity android:name=".activities.AddFriendsActivity"/>

        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.example.instapirate.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"></meta-data>
        </provider>
    </application>
</manifest>

The profile is edited using the EditProfileActivity file. There is a specific piece of code below, that takes pictures and changes the user's avatar, the link here works and is loaded into Storage and RealtimeDatabase in the normal form, but on Android 10 the photo is also not taken and the camera is reset:

 private lateinit var mUser: User
    private lateinit var mFirebase: FirebaseHelper
    private lateinit var mPendingUser: User
    private lateinit var mCamera: CameraHelper

    @SuppressLint("MissingSuperCall")
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == mCamera.REQUEST_CODE && resultCode == RESULT_OK) {
            mFirebase.uploadUserPhoto(mCamera.imageUri!!) {
                mFirebase.storageUid().addOnCompleteListener {
                    val photoUrl = it.result.toString()
                    mFirebase.updateUserPhoto(photoUrl){
                        mUser = mUser.copy(photo = photoUrl)
                        profile_image.loadUserPhoto(mUser.photo)
                    }
                }
            }
        }
    }

loadUserPhoto is in a separate utils file where all utilities are stored:

fun ImageView.loadUserPhoto(photoUrl: String?) =
    ifNotDestroyed {
        GlideApp.with(this).load(photoUrl).fallback(R.drawable.person).into(this)
    }

Remote classes that participate in the code above: CameraHelper

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Environment
import android.provider.MediaStore
import androidx.core.content.FileProvider
import java.io.File
import java.text.SimpleDateFormat
import java.util.*

class CameraHelper(private val activity: Activity) {
    var imageUri: Uri? = null
    val REQUEST_CODE = 1
    private val simpleDateFormat = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US)

    fun takeCameraPicture() {
        val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        if (intent.resolveActivity(activity.packageManager) != null) {
            val imageFile = createImageFile()
            imageUri = FileProvider.getUriForFile(activity,
                "com.example.instapirate.fileprovider",
                imageFile)
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri)
            activity.startActivityForResult(intent, REQUEST_CODE)
        }
    }
    private fun createImageFile(): File {
        val storageDir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
        return File.createTempFile(
            "JPEG_${simpleDateFormat.format(Date())}_",
            ".jpg",
            storageDir
        )
    }
}

FirebaseHelper

import android.app.Activity
import android.net.Uri
import com.example.instapirate.activities.showToast
import com.google.firebase.auth.AuthCredential
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.storage.StorageReference
import com.google.firebase.storage.UploadTask

class FirebaseHelper(private val activity: Activity) {
    val auth: FirebaseAuth = FirebaseAuth.getInstance()
    val database: DatabaseReference = FirebaseDatabase.getInstance().reference
    val storage: StorageReference = FirebaseStorage.getInstance().reference

    fun storageUid() = storage.child("users/${auth.currentUser!!.uid}/photo/").downloadUrl

    fun uploadUserPhoto(photo: Uri, onSuccess: (UploadTask.TaskSnapshot) -> Unit) {
        storage.child("users/${currentUid()!!}/photo").putFile(photo)
            .addOnCompleteListener {
                if (it.isSuccessful) {
                    onSuccess(it.result!!)
                } else {
                    activity.showToast(it.exception!!.message!!)
                }
            }
    }

    fun updateUserPhoto(photoUrl: String, onSuccess: () -> Unit) {
        database.child("users/${currentUid()!!}/photo").setValue(photoUrl)
            .addOnCompleteListener {
                if (it.isSuccessful) {
                    onSuccess()
                } else {
                    activity.showToast(it.exception!!.message!!)
                }
            }
    }

    fun updateUser(updates: Map<String, Any?>, onSuccess: () -> Unit) {
        database.child("users").child(currentUid()!!).updateChildren(updates)
            .addOnCompleteListener {
                if (it.isSuccessful) {
                    onSuccess()
                } else {
                    activity.showToast(it.exception!!.message!!)
                }
            }
    }

    fun updateEmail(email: String, onSuccess: () -> Unit) {
        auth.currentUser!!.updateEmail(email).addOnCompleteListener {
            if (it.isSuccessful) {
                onSuccess()
            } else {
                activity.showToast(it.exception!!.message!!)
            }
        }
    }

    fun reauthenticate(credential: AuthCredential, onSuccess: () -> Unit) {
        auth.currentUser!!.reauthenticate(credential).addOnCompleteListener {
            if (it.isSuccessful) {
                onSuccess()
            } else {
                activity.showToast(it.exception!!.message!!)
            }
        }
    }

    fun currentUserReference(): DatabaseReference =
        database.child("users").child(currentUid()!!)

    fun currentUid(): String? =
        auth.currentUser?.uid

}

There is also a ShareActivity file that implements uploading photos to the feed, and this is where problems with Firebase appear, since it is here that the links are displayed in an incorrect form (the screenshot of the feed was above). It happens if the photo was taken on Android 8 through the emulator. (on the phone with Android 10 after saving the photo the camera reopens and I have to take pictures again and so on in a circle)

class ShareActivity : BaseActivity(2) {
    private val TAG = "ShareActivity"
    private lateinit var mCamera: CameraHelper
    private lateinit var mFirebase: FirebaseHelper
    private lateinit var mUser: User

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_share)
        Log.d(TAG, "onCreate")

        mFirebase = FirebaseHelper(this)
        mCamera = CameraHelper(this)
        mCamera.takeCameraPicture()

        back_image.setOnClickListener{finish()}
        share_text.setOnClickListener{ share()}

        mFirebase.currentUserReference().addValueEventListener(ValueEventListenerAdapter{
            mUser = it.asUser()!!
        })
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == mCamera.REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                GlideApp.with(this).load(mCamera.imageUri).centerCrop().into(post_image)
            } else {
                finish()
            }
        }
    }

    private fun share() {
        val imageUri = mCamera. imageUri
        if (imageUri != null) {
            val uid = mFirebase.currentUid()!!
            mFirebase.storage.child("users").child(uid).child("images")
                .child(imageUri.lastPathSegment.toString()).putFile(imageUri).addOnCompleteListener{
                    if (it.isSuccessful){
                        val imageDownloadUrl = it.result!!.toString()
                        mFirebase.database.child("images").child(uid).push()
                            .setValue(imageDownloadUrl)
                            .addOnCompleteListener {
                                if (it.isSuccessful) {
                                    mFirebase.database.child("feed-posts").child(uid)
                                        .push()
                                        .setValue(mkFeedPost(uid, imageDownloadUrl))
                                        .addOnCompleteListener {
                                            if (it.isSuccessful) {
                                                startActivity(Intent(this,
                                                    ProfileActivity::class.java))
                                                finish()
                                            }
                                        }
                                } else {
                                    showToast(it.exception!!.message!!)
                                }
                            }
                    } else {
                        showToast(it.exception!!.message!!)
                    }
                }
        }
    }

    private fun mkFeedPost(uid: String, imageDownloadUrl: String): FeedPost {
        return FeedPost(
            uid = uid,
            username = mUser.username,
            image = imageDownloadUrl,
            caption = caption_input.text.toString(),
            photo = mUser.photo
        )
    }
}

When trying to save a photo on android 10, the following text appears in Debug (it was not possible to show the entire error due to restrictions, but I think this is an important part of the error):

2022-03-20 19:05:55.711 29351-29351/? I/ple.instapirat: Late-enabling -Xcheck:jni
2022-03-20 19:05:55.855 29351-29351/? E/ple.instapirat: Unknown bits set in runtime_flags: 0x8000
2022-03-20 19:05:56.943 29351-29351/com.example.instapirate I/Perf: Connecting to perf service.
2022-03-20 19:05:57.016 29351-29351/com.example.instapirate I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
2022-03-20 19:05:57.126 29351-29351/com.example.instapirate D/FirebaseAuth: Notifying id token listeners about user ( PjHBujbeapTQxmLl4TgzhgOTzjo2 ).
2022-03-20 19:05:57.158 29351-29351/com.example.instapirate I/FirebaseInitProvider: FirebaseApp initialization successful
2022-03-20 19:05:57.194 29351-29422/com.example.instapirate I/DynamiteModule: Considering local module com.google.android.gms.measurement.dynamite:69 and remote module com.google.android.gms.measurement.dynamite:67
2022-03-20 19:05:57.194 29351-29422/com.example.instapirate I/DynamiteModule: Selected local version of com.google.android.gms.measurement.dynamite
2022-03-20 19:05:57.263 29351-29424/com.example.instapirate E/Perf: Fail to get file list com.example.instapirate
2022-03-20 19:05:57.264 29351-29424/com.example.instapirate E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2022-03-20 19:05:57.427 29351-29425/com.example.instapirate I/FA: App measurement initialized, version: 60000
2022-03-20 19:05:57.427 29351-29425/com.example.instapirate I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2022-03-20 19:05:57.428 29351-29425/com.example.instapirate I/FA: To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.example.instapirate
2022-03-20 19:05:57.428 29351-29425/com.example.instapirate D/FA: Debug-level message logging enabled
2022-03-20 19:05:57.554 29351-29351/com.example.instapirate W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@6dd3e0e
2022-03-20 19:05:57.825 29351-29351/com.example.instapirate W/ple.instapirat: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
2022-03-20 19:05:57.827 29351-29351/com.example.instapirate W/ple.instapirat: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
2022-03-20 19:05:58.076 29351-29351/com.example.instapirate D/ShareActivity: onCreate
2022-03-20 19:05:58.332 29351-29425/com.example.instapirate I/FA: Tag Manager is not found and thus will not be used
2022-03-20 19:05:58.417 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.441 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.443 29351-29511/com.example.instapirate I/chatty: uid=10260(com.example.instapirate) glide-source-th identical 1 line
2022-03-20 19:05:58.444 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.451 29351-29519/com.example.instapirate D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2022-03-20 19:05:58.467 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.472 29351-29511/com.example.instapirate D/skia: --- Failed to create image decoder with message 'unimplemented'
2022-03-20 19:05:58.571 29351-29439/com.example.instapirate I/AdrenoGLES: QUALCOMM build                   : 7331a27, Ieeb4a86f7b
    Build Date                       : 11/13/19
    OpenGL ES Shader Compiler Version: EV031.27.05.02
    Local Branch                     : 
    Remote Branch                    : 
    Remote Branch                    : 
    Reconstruct Branch               : 
2022-03-20 19:05:58.571 29351-29439/com.example.instapirate I/AdrenoGLES: Build Config                     : S L 8.0.12 AArch64
2022-03-20 19:05:58.608 29351-29439/com.example.instapirate I/AdrenoGLES: PFP: 0x005ff113, ME: 0x005ff066
2022-03-20 19:05:58.618 29351-29439/com.example.instapirate W/AdrenoUtils: <ReadGpuID_from_sysfs:194>: Failed to open /sys/class/kgsl/kgsl-3d0/gpu_model
2022-03-20 19:05:58.618 29351-29439/com.example.instapirate W/AdrenoUtils: <ReadGpuID:218>: Failed to read chip ID from gpu_model. Fallback to use the GSL path
2022-03-20 19:05:58.668 29351-29439/com.example.instapirate W/Gralloc3: mapper 3.x is not supported
2022-03-20 19:05:58.751 29351-29351/com.example.instapirate W/Glide: Load failed for content://com.example.instapirate.fileprovider/images/JPEG_20220320_190558_2535596221289941323.jpg with size [204x204]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There were 3 causes:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{AutoCloseInputStream->Object->Drawable}, LOCAL
        Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AutoCloseInputStream->GifDrawable->Drawable}
        Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AutoCloseInputStream->Bitmap->Drawable}
        Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AutoCloseInputStream->BitmapDrawable->Drawable}
      Cause (2 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{ParcelFileDescriptorInner->Object->Drawable}, LOCAL
    There were 2 causes:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptorInner->Bitmap->Drawable}
    There was 1 cause:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
        Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptorInner->BitmapDrawable->Drawable}
    There was 1 cause:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
      Cause (3 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{AssetFileDescriptor->Object->Drawable}, LOCAL
    There was 1 cause:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{AssetFileDescriptor->Bitmap->Drawable}
    There was 1 cause:
    java.io.IOException(java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA)
     call GlideException#logRootCauses(String) for more detail
          Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
      Cause (4 of 4): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{HierarchicalUri->Object->Drawable}, LOCAL
        Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{HierarchicalUri->Drawable->Drawable}
        Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{HierarchicalUri->Bitmap->Drawable}
2022-03-20 19:05:58.753 29351-29351/com.example.instapirate I/Glide: Root cause (1 of 3)
    java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
        at com.bumptech.glide.load.resource.bitmap.VideoDecoder.decode(VideoDecoder.java:185)
        at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:92)
        at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:70)
        at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:59)
        at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:76)
        at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:57)
        at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:524)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:488)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:474)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:426)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:390)
        at com.bumptech.glide.load.engine.SourceGenerator.onDataReadyInternal(SourceGenerator.java:148)
        at com.bumptech.glide.load.engine.SourceGenerator$1.onDataReady(SourceGenerator.java:76)
        at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:52)
        at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:70)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:434)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:390)
        at com.bumptech.glide.load.engine.SourceGenerator.onDataReadyInternal(SourceGenerator.java:148)
        at com.bumptech.glide.load.engine.SourceGenerator$1.onDataReady(SourceGenerator.java:76)
        at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:52)
        at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:70)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
        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:919)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)
     Caused by: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
        at android.media.MediaMetadataRetriever.setDataSource(Native Method)
        at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:142)
        at com.bumptech.glide.load.resource.bitmap.VideoDecoder$ParcelFileDescriptorInitializer.initialize(VideoDecoder.java:306)
        at com.bumptech.glide.load.resource.bitmap.VideoDecoder$ParcelFileDescriptorInitializer.initialize(VideoDecoder.java:301)
        at com.bumptech.glide.load.resource.bitmap.VideoDecoder.decode(VideoDecoder.java:173)
        at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:92) 
        at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:70) 
        at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:59) 
        at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:76) 
        at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:57) 
        at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:524) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:488) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:474) 

If more necessary data from the code is required, then I can edit the post and add them (it seems to me that I already attached too much code, I'm sorry, but it's all important). I hope someone can help me solve at least 1 problem.


Solution

  • Just added into FirebaseHelper this code:

        fun uploadSharePhoto(localPhotoUrl: Uri, onSuccess: (UploadTask.TaskSnapshot) -> Unit) =
            storage.child("users/${auth.currentUser!!.uid}").child("images")
                .child(localPhotoUrl.lastPathSegment!!)
                .putFile(localPhotoUrl)
                .addOnCompleteListener {
                    if (it.isSuccessful)
                        onSuccess(it.result!!)
                    else
                        activity.showToast(it.exception!!.message!!)
                }
    
        fun addSharePhoto(globalPhotoUrl: String, onSuccess: () -> Unit) =
            database.child("images").child(auth.currentUser!!.uid)
                .push().setValue(globalPhotoUrl)
                .addOnComplete { onSuccess() }
    
        private fun Task<Void>.addOnComplete(onSuccess: () -> Unit) {
            addOnCompleteListener {
                if (it.isSuccessful)
                    onSuccess()
                else
                    activity.showToast(it.exception!!.message!!)
            }
        }
    

    And in ShareActivity the share() function was edited:

        private fun share() {
            val imageUri = mCamera.imageUri
            if (imageUri != null) {
                mFirebase.uploadSharePhoto(imageUri) {
                    it.metadata!!.reference!!.downloadUrl.addOnSuccessListener {
                        mFirebase.addSharePhoto(it.toString()) {
                            mFirebase.database.child("feed-posts").child(mFirebase.auth.currentUser!!.uid)
                                .push()
                                .setValue(mkFeedPost(mFirebase.auth.currentUser!!.uid, it.toString()))
                                .addOnCompleteListener {
                                    if (it.isSuccessful) {
                                        startActivity(Intent(this,
                                            ProfileActivity::class.java))
                                        finish()
                                    }
                                }
                        }
                    }
                }
            }
        }
    

    Now all the links are correct