Android: Check whether camera supports auto-focus?

前端 未结 5 1244
眼角桃花
眼角桃花 2020-12-31 02:17

For the Android API version 2.1 and higher, we can use context:

getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS)
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 02:56

    i'm guessing: Do not use the unknown constant.

    getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS)
    

    Should be:

    getPackageManager().hasSystemFeature("android.hardware.camera.autofocus")
    

    It was a short sight of the developers to use constants here. It solves the problem of knowing if a device, running an API that knows about a feature has a feature. but fails on the case you just mentioned... they really make supporting multiple api levels difficult.

    Updated: just tested it myself... PackageManager.hasSystemFeature() only showed up at API level 5. I was trying to add that check to my code that can very well support API level 3 (1.5) but which could benefit from camera's auto focus...seems like i have to choose support 1.5 or be able to use auto focus... or move my backward compatibility to level 5... or implement this http://www.java.net/forum/topic/java-tools/java-development-tools/wwyt-conditional-compilation-pre-process ...yeah, right.

    they really make it difficult to support multiple versions. So sorry 1.5 and 1.6 and 2.0 users. since my device is on 2.2 that will be my bottom line.

提交回复
热议问题