Check if device has a camera?

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

    try this

    For front camera

        Context context = this;
        PackageManager packageManager = context.getPackageManager();
        if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
    
            Utils.makeAlertDialog(context, "Has Front Camera ?", "YES");
    
        } else {
    
            Utils.makeAlertDialog(context, "Has Front Camera ?", "NO");
              }
    

    for back camera

        Context context = this;
        PackageManager packageManager = context.getPackageManager();
        if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
    
            Utils.makeAlertDialog(context, "Has back Camera ?", "YES");
    
        } else {
    
            Utils.makeAlertDialog(context, "Has back Camera ?", "NO");
              }
    

提交回复
热议问题