我想在尝试打开二维码阅读器之前检查设备是否有相机。
我有以下代码:
public boolean checkDeviceCompatibility() {
PackageManager pm = context.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
return true;
} else {
// use front camera
Toast.makeText(
context,
"This device does not have a back camera so it has automatically reverted to the front camera",
Toast.LENGTH_SHORT).show();
return true;
}
} else {
util.displayErrorDialog(
context,
"This device does not have any cameras and therefore cannot make use of the QR Code feature.");
return false;
}
}
但是现在,如果我用两个摄像头在银河S3上以调试模式运行此代码。第一个if语句返回false。
为什么会这样呢?
最佳答案
对于任何4.2之前的设备,FEATURE_CAMERA_ANY
was added in Android 4.2. hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
应该返回false
。如果您的S3仍为4.1,则可以解释您的问题。