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