Stack Overflow en español Asked by Xavy2605 on January 8, 2021
Estoy haciendo un widget para encender y apagar el flash de la cámara. Logro que encienda el el flash, pero cuando lo apago me da el siguiente error:
"Attempt to invoke virtual method ‘boolean java.lang.String.equals(java.lang.Object)’ on a null object reference"
Adjunto el código implementado para la revisión
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (intent.getAction().equals("encender")){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ){
try {
cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
if (cameraManager != null) {
cameraId = cameraManager.getCameraIdList()[0];
cameraManager.setTorchMode(cameraId, true);
Toast.makeText(context.getApplicationContext(), "Encendido", Toast.LENGTH_SHORT).show();
}
}
catch (CameraAccessException e) {
e.printStackTrace();
}
}
}
else {
if (intent.getAction().equals("apagar")){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
try {
cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
if (cameraManager != null) {
cameraId = cameraManager.getCameraIdList()[0];
cameraManager.setTorchMode(cameraId, false);
Toast.makeText(context.getApplicationContext(), "Apagado", Toast.LENGTH_SHORT).show();
}
}
catch (CameraAccessException e) {
e.printStackTrace();
}
}
}
}
}
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP