【发布时间】:2015-03-30 17:12:25
【问题描述】:
无论我是使用模拟摄像头还是将网络摄像头用作模拟设备的摄像头,我都无法保存照片。我的代码设置了一个新文件来保存照片,相机活动弹出,但在我拍照后,点击“保存”或“接受图片”按钮没有任何作用。我可以通过点击取消返回到我的应用程序活动的唯一方法。此代码在我的 Galaxy S3 上运行时有效,但不是在模拟的 Nexus 设备上运行。当我在 AVD Manager 中设置设备时,我始终确保能够将两个摄像头设置为仿真或网络摄像头0,无论我使用的是哪个,我确保有一张 SD 卡(即使我保存到内部存储器)和内部存储足够照片。在我的清单中,我声明了 android.permission.INTERNET、android.permission.WRITE_EXTERNAL_STORAGE 和 android.permission.CAMERA。有什么想法吗?
这是我启动相机意图的代码:
private void dispatchTakePictureIntent(int position) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile(position);
} catch (IOException ex) {
Log.v("photo", "photoFile failed.");
}
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
} else {
Log.v("tag", "photoFile was equal to null.");
}
}
}
【问题讨论】:
-
快速说明,使用
Log.e("photo", "photoFile failed.", ex);代替Log.v("photo", "photoFile failed.");可以更好地记录错误
标签: android camera android-emulator