从 Froyo 到 Ice Cream Sandwich ,就是这样:
Intent intent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
tempUriCameraDeviceNotSuported = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
tempUriCameraDeviceNotSuported);
startActivityForResult(intent, 0);
但是对于 Jelly Bean 来说它不起作用,你必须这样做:
Intent takePicture = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);
我不确定这个错误是否只发生在果冻 bean 上,或者也取决于硬件型号。谷歌没有提及这个问题(为什么?为什么?)。有人知道我在哪里可以找到包含所有设备及其正确相机实现的列表?有人知道最好的方法吗?
最佳答案
您可以随时检查操作系统版本:
if (android.os.Build.VERSION.SDK_INT >= 17) {
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePicture, 0);
} else {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
"test.jpg");
tempUriCameraDeviceNotSuported = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
tempUriCameraDeviceNotSuported);
startActivityForResult(intent, 0);
}
关于android - 有什么方法可以对所有级别的 api 进行安全的相机 Intent 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14382720/