Check if device has a camera?

前端 未结 14 1212
粉色の甜心
粉色の甜心 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:27

    Try this :

    /** Check if this device has a camera */
    private boolean checkCameraHardware(Context context) {
        if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
            // this device has a camera
            return true;
        } else {
            // no camera on this device
            return false;
        }
    }
    

    from : http://developer.android.com/guide/topics/media/camera.html

提交回复
热议问题