Camera.getNumberOfCameras() not working on Android 2.2

此生再无相见时 提交于 2019-12-01 15:45:27

问题


I am trying to use API Camera.getNumberOfCameras() but getting 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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5548323/camera-getnumberofcameras-not-working-on-android-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!