I am trying to set the onActivityResult on a kotlin class after a picture is taken or attached from the local files. The java code is working fine
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CameraService.REQUEST_IMAGE_CAPTURE) {
if (resultCode == Activity.RESULT_OK) {
photoList.add(mPhotoFile.toString());
}
}else{
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
photoList.add(picturePath);
}
}
}
But on a kotlin class, that same block of code gives me an error "The following declarations have the same JVM signature"
This is the kotlin code
private fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
if (requestCode == CameraService.REQUEST_IMAGE_CAPTURE) {
if (resultCode == Activity.RESULT_OK) {
photoList.add(mPhotoFile.toString())
}
} else {
if (resultCode == Activity.RESULT_OK) {
val selectedImage = data.data
val filePathColumn = arrayOf(MediaStore.Images.Media.DATA)
val cursor = contentResolver.query(selectedImage, filePathColumn, null, null, null)
cursor.moveToFirst()
val columnIndex = cursor.getColumnIndex(filePathColumn[0])
val picturePath = cursor.getString(columnIndex)
cursor.close()
photoList.add(picturePath)
}
}
}
Any help or suggestion would be great thanks
You should change your code like
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
if (requestCode == CameraService.REQUEST_IMAGE_CAPTURE) {
if (resultCode == Activity.RESULT_OK) {
photoList.add(mPhotoFile.toString())
}
} else {
if (resultCode == Activity.RESULT_OK) {
val selectedImage = data.data
val filePathColumn = arrayOf(MediaStore.Images.Media.DATA)
val cursor = contentResolver.query(selectedImage, filePathColumn, null, null, null)
cursor.moveToFirst()
val columnIndex = cursor.getColumnIndex(filePathColumn[0])
val picturePath = cursor.getString(columnIndex)
cursor.close()
photoList.add(picturePath)
}
}
}