public class ledFlash { Context context; CameraManager mCameraManager; String mCameraID; @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) ledFlash(Context context){ this.context = context; mCameraManager = (CameraManager)context.getSystemService(Context.CAMERA_SERVICE); try { final String[] list = mCameraManager.getCameraIdList(); mCameraID = list[0]; } catch (CameraAccessException e) { Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); } } @RequiresApi(api = Build.VERSION_CODES.M) public void toggle(boolean enable) { try { mCameraManager.setTorchMode(mCameraID, enable); }catch (Exception e) { Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); } } }
android 驱动闪光灯
最新推荐文章于 2022-10-30 20:31:23 发布