我正在使用这段相当简单的代码在Android设备上捕获图像。
File tmpFile = ...;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tmpFile));
startActivityForResult(intent, CAPTURE_IMAGE);
这适用于成千上万的用户,除了在没有摄像头的Kindle设备上运行此用户。今天我收到了带摄像头的设备的崩溃报告:
ANDROID_VERSION=4.2.1
BRAND=Hisense
PHONE_MODEL=M470BSA
STACK_TRACE=android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.media.action.IMAGE_CAPTURE (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
at android.app.Activity.startActivityForResult(Activity.java:3370)
at android.app.Activity.startActivityForResult(Activity.java:3331)
...
我已经对代码进行了一些异常处理以捕获异常并显示错误,但我不知道为什么这段代码在此设备上失败。用户确认相机工作正常。
答案 0 :(得分:0)
首先,即使设备有实际的摄像头,也不要求设备具有支持ACTION_IMAGE_CAPTURE
的活动。
其次,特别是在Android 4.3+平板电脑上,使用该设备的人可能无法访问ACTION_IMAGE_CAPTURE
活动,即使已安装了该活动,因为此人可能在受限制的个人资料中运行。