下面是摄像头的示例代码:
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivityForResult(intent, REQUEST_CAMERA)
Note: when I press back from camera as result on Activity result show like this:
JAVAlang.RuntimeException:未能将结果ResultInfo{who=null,request=65537,result=0,data=null}传递给活动
Try to come out solution like this :
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
try {
when(resultCode){
Activity.RESULT_CANCELED -> {
System.out.println("nothing")
}
Activity.RESULT_OK -> {
if (requestCode == SELECT_FILE)
onSelectFromGalleryResult(data)
else if (requestCode == REQUEST_CAMERA)
onCaptureImageResult(data)
}
}
}catch (e:NullPointerException){
e.printStackTrace()
}
}
still not solve the problem because when i do debuging log it not come out on func onactivityresult if i go press go back from camera and not capture the image. Taking picture and pickup image from gallery work like charm.
非常感谢.请帮我解决这个问题,因为一路上解决方案不起作用.谷歌似乎不得不在resultactivity(resultcode!!:Int)上覆盖乐趣<;-这个应该返回非null.