我正在使用已弃用的Android相机对象。我在这里读到: https://source.android.com/devices/camera/versioning.html
即使相机对象已被弃用,它仍应适用于Android 5.0+版本。我问这个,因为我发布了一个使用已弃用的相机对象的应用程序,我的朋友们下载了应用程序并且崩溃了。他们报告了错误,我在跟踪堆栈中看到相机甚至无法打开。这个应用程序适用于我的手机,我的手机是5.0+版本。所以也许我没有正确打开相机???或者这些手机可能无法使用已弃用的类。这是打开相机的代码:
@Override
public void onResume() {
super.onResume();
if(!StopTouch)//ignore this condition not relevant to the problem
StartUpCam();
}
private void StartUpCam()
{
if(faceProc==null)//ignore this as well
faceProc = FacialProcessing.getInstance();
camera=Camera.open(getCid()); //crashes here!!! Calls getCid() which is defined below
camera.setPreviewCallback(this);
initPreview(width, height);
startPreview();
startTimer();
}
private int getCid()
{
if(cameraFront && findFrontFacingCamera()>0)
return findFrontFacingCamera();
return findBackFacingCamera();
}
public static int findBackFacingCamera() {
int cameraId = -1;
int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; i++) {
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
cameraId = i;
break;
}
}
return cameraId;
}
public static int findFrontFacingCamera() {
int cameraId = -1;
int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; i++) {
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
cameraId = i;
break;
}
}
return cameraId;
}
其他人在发布应用时遇到了已弃用的相机类问题?我在这里做错了什么想法?
答案 0 :(得分:2)
If you tried to run it in Android Marshmallow you need to ask for permission dynamically rather than just declaring the Camera permission in manifest. Here's a list of permissions which need to be asked dynamically from marshmallow http://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
答案 1 :(得分:0)
如果你想删除&#34;已弃用&#34;在您的应用中,使用camera2检查文档: