使用下面的接口,看下打开关闭camera是否能得到通知,然后做一个service
CameraManager
AvailabilityCallback
public static abstract class AvailabilityCallback {607608 /**609 * A new camera has become available to use.610 *611 * <p>The default implementation of this method does nothing.</p>612 *613 * @param cameraId The unique identifier of the new camera.614 */615 public void onCameraAvailable(@NonNull String cameraId) {616 // default empty implementation617 }618619 /**620 * A previously-available camera has become unavailable for use.621 *622 * <p>If an application had an active CameraDevice instance for the623 * now-disconnected camera, that application will receive a624 * {@link CameraDevice.StateCallback#onDisconnected disconnection error}.</p>625 *626 * <p>The default implementation of this method does nothing.</p>627 *628 * @param cameraId The unique identifier of the disconnected camera.629 */630 public void onCameraUnavailable(@NonNull String cameraId) {631 // default empty implementation632 }633 }
使用通知管理器来显示UI图标:
//创建一个通知管理器
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);