In my application I am using the Smartphone's flash light when a Notification arrives. When a new Push notification arrives the following function gets executed.
private static void flashlight(final Context context, final String userId) {
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
if (cameraManager != null) {
String cameraId = cameraManager.getCameraIdList()[0];
if (cameraId != null) {
for (i = 0; i < 50; i++) {
cameraManager.setTorchMode(cameraId, true);
SystemClock.sleep(100);
cameraManager.setTorchMode(cameraId, false);
SystemClock.sleep(100);
}
cameraManager.setTorchMode(cameraId, false);
}
}
} catch (Exception e) {
Log.e("PushCreator_flashlight", e.toString());
}
}
};
Thread thread = new Thread(runnable);
thread.start();
}
}
I also have the permissions in the Manifest file:
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
It's working but the only problem I have is that the following Error is thrown the entire time the flash light gets used.
I already checked out the following question but it did not work: Access denied for property “vendor.camera.aux.packagelist”
Does somebody know how I can solve this problem.