我在我的应用程序中使用camera2 api,但是一些像Redmi note 3这样的设备即使这些设备使用棒棒糖安卓版也不支持它。现在我的查询是如何在我的应用程序中检查设备是否支持camera2 api
答案 0 :(得分:0)
尝试以下代码
检查设备中是否有前置摄像头
public static boolean checkCameraFront(Context context) {
if(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
return true;
} else {
return false;
}
}
检查设备中是否有后置摄像头
public static boolean checkCameraRear() {
int numCamera = Camera.getNumberOfCameras();
if(numCamera > 0) {
return true;
} else {
return false;
}
}
答案 1 :(得分:0)
所有通过认证的Android设备都支持从API级别21(Lollipop)开始的camera2 API。
某些设备可能不支持所有可能的功能,例如手动控制或RAW捕获,但基本API应始终有效。
答案 2 :(得分:0)
请访问this我希望它对您有所帮助
答案 3 :(得分:0)
以下是确定设备中哪些摄像头具有Full或Limited Camera2 API支持的片段(只需调用checkCamera2Support方法):
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean allowCamera2Support(int cameraId) {
CameraManager manager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
try {
String cameraIdS = manager.getCameraIdList()[cameraId];
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraIdS);
int support = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY )
Log.d(TAG, "Camera " + cameraId + " has LEGACY Camera2 support");
else if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED )
Log.d(TAG, "Camera " + cameraId + " has LIMITED Camera2 support");
else if( support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL )
Log.d(TAG, "Camera " + cameraId + " has FULL Camera2 support");
else
Log.d(TAG, "Camera " + cameraId + " has unknown Camera2 support?!");
return support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED || support == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL;
}
catch (CameraAccessException e) {
e.printStackTrace();
}
return false;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void checkCamera2Support() {
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) {
if( getNumberOfCameras() == 0 ) {
Log.d(TAG, "0 cameras");
}else {
for (int i = 0; i < getNumberOfCameras(); i++) {
if (!allowCamera2Support(i)) {
Log.d(TAG, "camera " + i + " doesn't have limited or full support for Camera2 API");
}else{
// here you can get ids of cameras that have limited or full support for Camera2 API
}
}
}
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public int getNumberOfCameras() {
CameraManager manager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
try {
return manager.getCameraIdList().length;
} catch (CameraAccessException e) {
e.printStackTrace();
} catch(AssertionError e) {
e.printStackTrace();
}
return 0;
}