Tesis 1.0.0
Loading...
Searching...
No Matches
ImageUpdateReceiver.java
Go to the documentation of this file.
1package com.example.food_front.utils;
2
3import android.content.BroadcastReceiver;
4import android.content.Context;
5import android.content.Intent;
6import android.content.IntentFilter;
7import android.util.Log;
8
14public class ImageUpdateReceiver extends BroadcastReceiver {
15
16 public static final String ACTION_IMAGE_UPDATED = "com.example.food_front.IMAGE_UPDATED";
17 public static final String EXTRA_IMAGE_URL = "image_url";
18
19 private ImageUpdateListener listener;
20
25 this.listener = listener;
26 }
27
28 @Override
29 public void onReceive(Context context, Intent intent) {
30 if (ACTION_IMAGE_UPDATED.equals(intent.getAction())) {
31 String imageUrl = intent.getStringExtra(EXTRA_IMAGE_URL);
32 Log.d("ImageUpdateReceiver", "Recibida notificación de actualización de imagen: " + imageUrl);
33
34 if (listener != null) {
35 listener.onImageUpdated(imageUrl);
36 }
37 }
38 }
39
43 public void register(Context context) {
44 IntentFilter filter = new IntentFilter(ACTION_IMAGE_UPDATED);
45 context.registerReceiver(this, filter);
46 }
47
51 public void unregister(Context context) {
52 try {
53 context.unregisterReceiver(this);
54 } catch (Exception e) {
55 Log.e("ImageUpdateReceiver", "Error al desregistrar: " + e.getMessage());
56 }
57 }
58
62 public static void notifyImageUpdated(Context context, String imageUrl) {
63 Intent intent = new Intent(ACTION_IMAGE_UPDATED);
64 intent.putExtra(EXTRA_IMAGE_URL, imageUrl);
65 context.sendBroadcast(intent);
66 Log.d("ImageUpdateReceiver", "Enviada notificación de actualización de imagen: " + imageUrl);
67 }
68
72 public interface ImageUpdateListener {
73 void onImageUpdated(String imageUrl);
74 }
75}
void onReceive(Context context, Intent intent)
static void notifyImageUpdated(Context context, String imageUrl)