Original answer from StackOverflow:
Usage:
val intent = Intent(Intent.ACTION_GET_CONTENT)
intent.putExtra("viewId", myViewIdParam)
intent.setType("image/*")
context.setIntent(intent)
context.startActivityForResult(intent, REQUEST_IMAGE_PICK)
val resultIntent = intent
resultIntent.putExtra("viewId", intent.getIntExtra("viewId", -1));
setResult(RESULT_OK, resultIntent);
finish();
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_IMAGE_PICK && data != null) {
val viewId = data.getIntExtra("viewId", intent.getIntExtra("viewId", -1))
// todo your stuff here
}
}