简体   繁体   中英

getCameraIdList() function returns an empty array

I'm trying to work with Android's camera API 2, and I had a bug which I wasn't able to fix. The function getCameraIdList() returns an empty array for some reason, although I do have 2 working cameras on my emulator (I checked it using the Android camera app). I am working on an emulated device with the following details: Device: Nexus S API level: androd 4.4.2, API level 19 CPU: intel atom x86 front & back camera are emulated

what do you think? attached is the code.

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

函数getCameraIdList仅适用于Android API版本21

Here are four things that might get the app to start working again. One of these four have always done the trick for me when the I get the error.

  1. Switch to another app and then back to the camera app.
    Hit the back button to exit the camera app and then tap to open it again. This has the least success rate, to be honest, but it does work and it's the quickest solution.
  2. Exit all apps that might be using the camera. Go to Settings>Battery and check if mm-qcamera-daemon is running. Exit it and launch the app again to see if the camera connects.
  3. Exit the app and relaunch it. This works most times. If it doesn't try to force stop the app and clear the cache. The measures sound drastic but it has a high success rate.
  4. If all else fails, restart your phone.
    Exit every app that's running before restart it. I found this to work when nothing else would and so far the error hasn't popped up again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM