2012-07-12 18 views
5

Estoy desarrollando un widget de calendario y no puedo recibir el mensaje DATE_CHANGED cuando cambié la fecha MANUALMENTE.El widget de Android no puede recibir el mensaje DATE_CHANGED

¿Cuál es el problema?

Mi código de manifiesto es:

<receiver android:name="com.widget.calendar.CalendarWidgetProvider"> 
    <intent-filter> 
     <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     <action android:name="android.intent.action.DATE_CHANGED"/> 
    </intent-filter> 
    <!-- This specifies the widget provider info --> 
    <meta-data android:name="android.appwidget.provider" 
     android:resource="@xml/widgetinfo" /> 
</receiver> 

Y trató de recibirlo como esto:

@Override 
public void onReceive(Context ctx, Intent intent) { 
    final String action = intent.getAction(); 
    if (action.equalsIgnoreCase("android.intent.action.DATE_CHANGED")) { 
     Log.e(TAG, "Date changed.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 
    } 
    super.onReceive(ctx, intent); 
} 

Sin embargo, el registro no se imprime cuando cambio la fecha del sistema manualmente.

Gracias!

ACTUALIZACIÓN:

He resuelto esto con Intent.ACTION_TIME_CHANGED, es realmente un error de DATE_CHANGED.

Respuesta

7

Utilice esta intención:

<intent-filter> 
     <action android:name="android.intent.action.TIME_SET"/> 
</intent-filter> 

y reciba:

@Override 
public void onReceive(Context ctx, Intent intent) { 
    final String action = intent.getAction(); 
    if (action.equalsIgnoreCase("android.intent.action.TIME_SET")) { 
     Log.e(TAG, "Date changed.....!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 
    } 
    super.onReceive(ctx, intent); 
} 
+0

pero esto hará que el agotamiento de la batería, ya que llamará receptor de radiodifusión y otra vez cada vez que el tiempo va a cambiar. – Akram

+1

@ Akki He probado que no enviará este intento TIME_SET a menos que cambie la hora o fecha del sistema manualmente. Entonces la batería está a salvo aquí :) :) – herbertD

+0

así que ¿quiere llamar a este receptor cuando el usuario cambie la fecha manualmente? – Akram

Cuestiones relacionadas