How to download a image in gallery?

0

I have two errors wich takes me that is a problem with the DecodePath. I want to save a file, but I can't because of this error.

My errors:

   Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{ParcelFileDescriptor->BitmapDrawable->Drawable}
Cause (1 of 1): class java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0x80000000

This is where I tried to get the path of the file:

private suspend fun getWallpaperFile(photo: Photo): File = withContext(Dispatchers.IO) {
    val file = Glide.with(context)
        .downloadOnly()
        .load(photo.src?.portrait)
        .submit()
        .get()
    val renamedFile = File(
        file.parent,
        DEFAULT_FILE_NAME
    )

    file.renameTo(renamedFile)
    renamedFile
}

In this part I am saving my WallpaperFile in Gallery:(i can't save the file)

private suspend fun saveWallpaperInGallery(photo: Photo): String = withContext(Dispatchers.IO) {
    val context = context
    val wallpaperFile = getWallpaperFile(photo)
    val wallpaperUri = MediaStore.Images.Media.insertImage(
        context.contentResolver,
        wallpaperFile.path, wallpaperFile.name, "By ${photo.photographer}"
    )
    val intent = Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE).apply {
        data = Uri.parse(wallpaperUri)
    }
    context.sendBroadcast(intent)

    wallpaperUri
}

I want to able to save Wallpaper File into Gallery. I think the problem is that I didn't decode the File. I'm not 100% sure that this is the main problem.

Hope guys you can help me with some ideas or even to get me the solution.

android
decode
android-glide
asked on Stack Overflow May 17, 2019 by android • edited May 17, 2019 by android

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0