79238169

Date: 2024-11-29 19:27:37
Score: 1.5
Natty:
Report link

I faced same issue and i find this uri

I have tried above solution and many solution but it did not work for me i am saving and load image from firebase

Actually Every app has its internal and external storage , For access external storage of any app we need permission and when we have that permission then we can access that external storage of app , in our case gallery is another app we want to access and image , videos are external storage .

i also use rememberLauncherForActivityResult that gave us temperarory access to external storage(image , videos) of gallery . so when we pick image then it return uri let say content uri , now if we save that content uri in some where like if if the app is offline etc we get image . and then we re run app then content uri we want to use in app then we can not do that because at that time we do not have permission to access to external storage of image

solution : convert the uri of image into byte array and then save in database etc

get imageByte array and then convert back to bitmap and then use in android

val launcher = rememberLauncherForActivityResult(
        contract = ActivityResultContracts.PickVisualMedia()
    ) { uri ->
        if(uri != null){
          bitmap = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                ImageDecoder.decodeBitmap(ImageDecoder.createSource(contentResolver, uri))
            } else {
                MediaStore.Images.Media.getBitmap(contentResolver, uri)
            }
            val imageByte = contentResolver.openInputStream(uri)?.use {
                it.readBytes()
            }
            MainActivity().uploadFile(imageByte!! , context)
        }
    }

For get data

MainActivity().loadImage(context) { byteArray ->
            if (byteArray != null) {
                bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
            }
        }
Reasons:
  • Blacklisted phrase (1): did not work
  • Blacklisted phrase (1.5): any solution
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: deadLock