ImagePicker icon indicating copy to clipboard operation
ImagePicker copied to clipboard

App is Crashing!

Open Manthan404 opened this issue 2 years ago • 1 comments

W/Glide: Load failed for null with size [0x0] class com.bumptech.glide.load.engine.GlideException: Received null model V/FA: Inactivity, disconnecting from the service

Manthan404 avatar Sep 16 '21 18:09 Manthan404

Use this code

private val startForProfileImageResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult -> val resultCode = result.resultCode val data = result.data

    if (resultCode == Activity.RESULT_OK) {
        //Image Uri will not be null for RESULT_OK
        val fileUri = data?.data!!

        mProfileUri = fileUri
        imgProfile.setImageURI(fileUri)
    } else if (resultCode == ImagePicker.RESULT_ERROR) {
        Toast.makeText(this, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
    } else {
        Toast.makeText(this, "Task Cancelled", Toast.LENGTH_SHORT).show()
    }
}

ImagePicker.with(this) .compress(1024) //Final image size will be less than 1 MB(Optional) .maxResultSize(1080, 1080) //Final image resolution will be less than 1080 x 1080(Optional) .createIntent { intent -> startForProfileImageResult.launch(intent) }

sumit-android-dev avatar Sep 30 '21 09:09 sumit-android-dev