0

Im making a register app, that allows the user to pick a picture via button, after the user pressed it, the background of the button should be the chosen picture, but instead it crashes, what could be the problem?

here is the code to open up the image picker via button

 button_selectphoto_register.setOnClickListener {
        val intent=Intent(Intent.ACTION_PICK)
        intent.type = "image/*"
        startActivityForResult(intent, 0)
    }

and here is the onActivityResult that should show the image on the button*/ NOTE: the getBitmap is crossed in android studio, it says that it is deprecated, i think that is what causing the problem, but i dont know what i should do

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
if (requestCode == 0 && resultCode == Activity.RESULT_OK && data != null){

    val uri = data.data

    val bitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri)
    val bitmapDrawable = BitmapDrawable(bitmap)
    button_selectphoto_register.setBackgroundDrawable(bitmapDrawable)
}
jaedster medina
  • 589
  • 1
  • 4
  • 7

1 Answers1

0

If you want to know the alternative code for getBitmap, then follow this link. As it says,

This method was deprecated in API level 29. Loading of images should be performed through ImageDecoder#createSource(ContentResolver, Uri)

SaadAAkash
  • 3,065
  • 3
  • 19
  • 25