private void updateWidget {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.led_widget, actionPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
}
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
super.onReceive(context, intent);
if (ACTION_WIDGET_RECEIVER.equals(action)) {
boolean light_on = intent.getBooleanExtra("power_on", true);
if(light_on) {
LedOn();
led_set_on = true;
} else {
LedOff();
led_set_on = false;
}
}
}
public void LedOn() {
mCamera = Camera.open();
if(mCamera!=null) {
Camera.Parameters params = mCamera.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
mCamera.setParameters(params);
} else {
Toast.makeText(null, "Ошибка доступа к камере", Toast.LENGTH_SHORT).show();
}
}
public void LedOff() {
Camera.Parameters params = mCamera.getParameters();
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
mCamera.setParameters(params);
mCamera.release();
mCamera = null;
}