1、判断设备是否支持拍照,就是检测是否有摄像头
private fun isCameraCanUse():Boolean{
var canUse = false
try {
val manager: CameraManager =
this.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val array = manager.cameraIdList
if(array.isNotEmpty()){
canUse = true
}
}catch (e:Exception){
canUse = false
}
return canUse
}
2、判断前置摄像头是否可用
private fun hasFrontFacingCamera():Boolean{
val manager: CameraManager =
this.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val array = manager.cameraIdList
for(a in array){
if(a=="0"){
return true
}
}
return false
}
3、判断后置摄像头是否可用
private fun hasBackFacingCamera():Boolean{
val manager: CameraManager =
this.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val array = manager.cameraIdList
for(a in array){
if(a=="1"){
return true
}
}
return false
}