当前位置: 首页>>代码示例>>Java>>正文


Java CameraManager.getCameraIdList方法代码示例

本文整理汇总了Java中android.hardware.camera2.CameraManager.getCameraIdList方法的典型用法代码示例。如果您正苦于以下问题:Java CameraManager.getCameraIdList方法的具体用法?Java CameraManager.getCameraIdList怎么用?Java CameraManager.getCameraIdList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.camera2.CameraManager的用法示例。


在下文中一共展示了CameraManager.getCameraIdList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera_v2);

    CameraManager cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
    try {
        for (String cameraId : cameraManager.getCameraIdList()) {
            CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
            if (facing != null && facing.equals(CameraCharacteristics.LENS_FACING_FRONT)) {

            }
            // Do something with the characteristics
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
开发者ID:akexorcist,项目名称:CameraSample,代码行数:20,代码来源:CameraV2Activity.java

示例2: doesUserHaveFrontFacingCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
/**
 * Checks if user has front facing camera.
 * @param context Context used to check
 * @return 0 For front facing, 1 for back facing, -1 for if it does not have front facing at all
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static int doesUserHaveFrontFacingCamera(Context context) {

    if(Build.VERSION.SDK_INT >= 21) {
        try {
            CameraManager cManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
            for (int j = 0; j < cManager.getCameraIdList().length; j++) {
                String[] cameraId = cManager.getCameraIdList();
                CameraCharacteristics characteristics = cManager.getCameraCharacteristics(cameraId[j]);
                int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
                if (cOrientation == CameraCharacteristics.LENS_FACING_FRONT)
                    return j;
            }
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
    return -1; // No front-facing camera found
}
 
开发者ID:PGMacDesign,项目名称:PGMacTips,代码行数:25,代码来源:CameraMediaUtilities.java

示例3: getCameraInfo

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@Override
protected String getCameraInfo() {
    String camStr = mContext.getString(R.string.camApi2) + "\n";
    CameraManager camManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
    try {
        for (String camId : camManager.getCameraIdList()) {
            camStr += mContext.getString(R.string.cameraId, camId) + ": ";

            CameraCharacteristics characteristics = camManager.getCameraCharacteristics(camId);
            Boolean hasFlash = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);

            camStr += (hasFlash ? mContext.getString(R.string.has) : mContext.getString(R.string.no))
                    + " " + mContext.getString(R.string.flash) + ", ";
            camStr += (facing == CameraCharacteristics.LENS_FACING_BACK ?
                    mContext.getString(R.string.backFacing) : mContext.getString(R.string.frontFacing)) + "\n";
        }
    } catch (CameraAccessException e) {
        camStr = mActivity.getString(R.string.failedAccessCamera) + ":" + e.getMessage();
    }

    return camStr.trim();
}
 
开发者ID:vbier,项目名称:habpanelviewer,代码行数:24,代码来源:MotionDetectorCamera2.java

示例4: isSupported

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
/**
 * Checks if API is supported and all cameras have better than legacy support.
 */
public static boolean isSupported(Context context) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    return false;
  }

  CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
  try {
    String[] cameraIds = cameraManager.getCameraIdList();
    for (String id : cameraIds) {
      CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(id);
      if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)
          == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return false;
      }
    }
    // On Android OS pre 4.4.2, a class will not load because of VerifyError if it contains a
    // catch statement with an Exception from a newer API, even if the code is never executed.
    // https://code.google.com/p/android/issues/detail?id=209129
  } catch (/* CameraAccessException */ AndroidException e) {
    Logging.e(TAG, "Camera access exception: " + e);
    return false;
  }
  return true;
}
 
开发者ID:Piasy,项目名称:VideoCRE,代码行数:28,代码来源:Camera2Enumerator.java

示例5: initData

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@TargetApi(23)
private void initData() {
    mCameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    mTorchCallback = new CameraManager.TorchCallback() {
        @Override
        public void onTorchModeChanged(String cameraId, boolean enabled) {
            super.onTorchModeChanged(cameraId, enabled);
            mShowTorchModeTV.setText("Camera:" + cameraId + " TorchMode change :" + enabled);
        }

        @Override
        public void onTorchModeUnavailable(String cameraId) {
            super.onTorchModeUnavailable(cameraId);
        }
    };
    try {
        mCameraIdList = mCameraManager.getCameraIdList();
    } catch (CameraAccessException e) {
        mCameraIdList = null;
        e.printStackTrace();
    }
    // 注册回调监听
    mCameraManager.registerTorchCallback(mTorchCallback, new Handler());
}
 
开发者ID:DIY-green,项目名称:AndroidStudyDemo,代码行数:25,代码来源:CameraTestActivity.java

示例6: GetAllCameras2

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static List<MyCameraInfo> GetAllCameras2(Context context) throws Exception {
    List<MyCameraInfo> cameras = new ArrayList<>();

    CameraManager cameraManager =
            (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);

    for (String cameraId : cameraManager.getCameraIdList()) {
        CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
        MyCameraInfo cameraInfo = MyCameraInfo.CreateFromCameraCharacteristics(cameraId,
                characteristics);
        cameras.add(cameraInfo);
    }

    return cameras;
}
 
开发者ID:tranquvis,项目名称:SimpleSmsRemote,代码行数:17,代码来源:CameraUtils.java

示例7: openCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private void openCamera() {

        CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);

        Log.d(TAG, "openCamera Start");
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
            try {
                cameraId = manager.getCameraIdList()[0];

                // setup the camera perview.  should wrap this in a checkpermissions, which studio is bitching about
                // except it has been done before this fragment is called.
                manager.openCamera(cameraId, mStateCallback, null);

            } catch (CameraAccessException e) {
                e.printStackTrace();
            }
        } else {
            Log.e(TAG, "Don't have permission to camera!");
        }
        Log.d(TAG, "openCamera End");
    }
 
开发者ID:JimSeker,项目名称:AudioVideo,代码行数:22,代码来源:Cam2Fragment.java

示例8: getCamerasCount

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static  int getCamerasCount(Context ctx)
{
    int count = 0;

    if(Build.VERSION.SDK_INT >= 21)
    {
        CameraManager manager = (CameraManager) ctx.getSystemService(Context.CAMERA_SERVICE);
        try
        {
            count = manager.getCameraIdList().length;

        } catch ( CameraAccessException e)
        {
            LogHelper.logx(e);
        }

    }
    else
    {
        count = Camera.getNumberOfCameras();
    }


    return count;
}
 
开发者ID:joseliko7,项目名称:Snapmatic-Life,代码行数:27,代码来源:CameraHelper.java

示例9: scanCode

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void scanCode() {

    try {
        CameraManager manager = (CameraManager) getApplicationContext().getSystemService(Context.CAMERA_SERVICE);
        String[] cameraIds = manager.getCameraIdList();
        for (int i = 0; i < cameraIds.length; i++) {
            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraIds[i]);
            if (characteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_BACK) {
                IntentIntegrator integrator = new IntentIntegrator(this);
                integrator.setCameraId(i);
                integrator.initiateScan();
            }
        }
    } catch (CameraAccessException e) {
    }

}
 
开发者ID:wcomartin,项目名称:PlexPy-Remote,代码行数:19,代码来源:ServerQRScannerActivity.java

示例10: init

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@Override
@TargetApi(Build.VERSION_CODES.M)
public void init(Context context) {
    mContext = context;
    mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    
    try {
        for(final String cameraId : mCameraManager.getCameraIdList()){
            CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(cameraId);
            int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
            if(cOrientation == CameraCharacteristics.LENS_FACING_BACK){
                mCameraID= cameraId;
            }
        }
        
        
    } catch (CameraAccessException e) {
        Toast.makeText(mContext, e.getMessage(), Toast.LENGTH_SHORT).show();
    }

}
 
开发者ID:SecUSo,项目名称:privacy-friendly-torchlight,代码行数:22,代码来源:CameraMarshmallow.java

示例11: camera2Id

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected String camera2Id(final int face)
//----------------------------------------
{
   try
   {
      CameraManager manager = (CameraManager) surfaceView.getContext().getSystemService(Context.CAMERA_SERVICE);
      String camList[] = manager.getCameraIdList();
      if (camList.length == 0)
         return null;
      CameraCharacteristics characteristics = null;
      for (String cameraID : camList)
      {
         characteristics = manager.getCameraCharacteristics(cameraID);
         Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
         if (facing == null) continue;
         if (face == facing)
            return cameraID;
      }
   }
   catch (Exception e)
   {
      return null;
   }
   return null;
}
 
开发者ID:donaldmunro,项目名称:AARemu,代码行数:27,代码来源:LegacyPreviewCamera.java

示例12: hasCamera2

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean hasCamera2(Context context) {
    if (context == null) return false;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return false;
    try {
        CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
        String[] idList = manager.getCameraIdList();
        boolean notNull = true;
        if (idList.length == 0) {
            notNull = false;
        } else {
            for (final String str : idList) {
                if (str == null || str.trim().isEmpty()) {
                    notNull = false;
                    break;
                }
                final CameraCharacteristics characteristics = manager.getCameraCharacteristics(str);

                final int supportLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
                if (supportLevel == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
                    notNull = false;
                    break;
                }
            }
        }
        return notNull;
    } catch (Throwable ignore) {
        return false;
    }
}
 
开发者ID:MartinRGB,项目名称:android_camera_experiment,代码行数:31,代码来源:CameraHelper.java

示例13: chooseCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private String chooseCamera() {
  final CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
  try {
    for (final String cameraId : manager.getCameraIdList()) {
      final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

      // We don't use a front facing camera in this sample.
      final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
      if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
        continue;
      }

      final StreamConfigurationMap map =
          characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

      if (map == null) {
        continue;
      }

      useCamera2API = isHardwareLevelSupported(characteristics,
          CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL);
      LOGGER.i("Camera API lv2?: %s", useCamera2API);
      return cameraId;
    }
  } catch (CameraAccessException e) {
    LOGGER.e(e, "Not allowed to access camera");
  }

  return null;
}
 
开发者ID:Nilhcem,项目名称:tensorflow-classifier-android,代码行数:31,代码来源:CameraActivity.java

示例14: init

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
private void init(Context context) throws CameraAccessException {
  inSession = false;

  if (!ImageSaver.isExternalStorageWritable()) {
    Timber.e("Cannot save file, external storage is not writable.");
    return;
  }

  File root = ImageSaver.getRoot(ROBOCAR_FOLDER);
  if (root == null) {
    Timber.e("Failed to create destination folder.");
    return;
  }

  CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
  String[] cameras = manager.getCameraIdList();
  if (cameras.length == 0) {
    Timber.e("No cameras available.");
    return;
  }

  Timber.d("Default camera selected (%s), %d cameras found.",
      cameras[CAMERA_INDEX], cameras.length);

  if (ActivityCompat.checkSelfPermission(
      context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
    Timber.d("Camera permission not granted yet, restart your device.");
    return;
  }

  // Debug and check for autofocus support
  dumpFormatInfo(manager, cameras[CAMERA_INDEX]);

  startBackgroundThread();
  deviceCallback = new DeviceCallback();
  manager.openCamera(cameras[CAMERA_INDEX], deviceCallback, backgroundHandler);
}
 
开发者ID:zugaldia,项目名称:android-robocar,代码行数:38,代码来源:CameraOperator.java

示例15: initializeCamera

import android.hardware.camera2.CameraManager; //导入方法依赖的package包/类
/**
 * Initialize the camera device
 */
public void initializeCamera(Context context,
                             Handler backgroundHandler,
                             ImageReader.OnImageAvailableListener imageAvailableListener) {
    // Discover the camera instance
    CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    String[] camIds = {};
    try {
        camIds = manager.getCameraIdList();
    } catch (CameraAccessException e) {
        Log.d(TAG, "Cam access exception getting IDs", e);
    }
    if (camIds.length < 1) {
        Log.d(TAG, "No cameras found");
        return;
    }
    String id = camIds[0];
    Log.d(TAG, "Using camera id " + id);
    // Initialize the image processor
    mImageReader = ImageReader.newInstance(IMAGE_WIDTH, IMAGE_HEIGHT,
            ImageFormat.JPEG, MAX_IMAGES);
    mImageReader.setOnImageAvailableListener(
            imageAvailableListener, backgroundHandler);
    // Open the camera resource
    try {
        manager.openCamera(id, mStateCallback, backgroundHandler);
    } catch (CameraAccessException cae) {
        Log.d(TAG, "Camera access exception", cae);
    }
}
 
开发者ID:googlecodelabs,项目名称:androidthings-imageclassifier,代码行数:33,代码来源:CameraHandler.java


注:本文中的android.hardware.camera2.CameraManager.getCameraIdList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。