开发者

Camera.getNumberOfCameras() not working on Android 2.2

开发者 https://www.devze.com 2023-02-21 22:07 出处:网络
I am trying to use API Camera.getNumberOfCameras() but ge开发者_StackOverflow中文版tting error \"Cannot find symbol\" while compiling. My API level is 8.

I am trying to use API Camera.getNumberOfCameras() but ge开发者_StackOverflow中文版tting error "Cannot find symbol" while compiling. My API level is 8. Can anyone please tell me whats the way to get this function work?

Thanks.


That method was not introduced until API Level 9 (Android 2.3). You cannot use it on older versions of Android. Here is a sample project demonstrating how to use it on newer versions of Android while safely avoiding it on older versions of Android.


I know its an old post.But updating for new comers.

From API21 Camera class is deprecated.Instead we have to use Camera2 class. For gettng connected devices,you have to use something like

private CameraManager mManager;
private String[] mCameraIds;
mManager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
mCameraIds = mManager.getCameraIdList();

You can find documentation here

0

精彩评论

暂无评论...
验证码 换一张
取 消