Check if device has a camera?

前端 未结 14 1238
粉色の甜心
粉色の甜心 2020-11-30 21:59

In my app, I\'d like to use the camera, if the device has one. Are there any devices running android that do not have a camera? By including the following into my m

14条回答
  •  醉酒成梦
    2020-11-30 22:10

    As per the documentation, you have to use Package Manager to check if Camera is available on the device or not

    In Java:

    final boolean isCameraAvailable = getPackageManager().hasSystemFeature(FEATURE_CAMERA);
    

    In Kotlin:

    val isCameraAvailable = packageManager.hasSystemFeature(FEATURE_CAMERA)
    

提交回复
热议问题