سؤال

i have a digital widget clock that works nicely!! but the problem here is that it doesn't update i mean it just shows the time of that moment that i add that to home screen!!!

in widget.java: I have an onUpdate like this:

Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {

    super.onUpdate(context, appWidgetManager, appWidgetIds);
for (int i = 0; i < appWidgetIds.length; i++) {

    int appWidgetId = appWidgetIds[i];

and then inside of onUpdate first i have used the Time method to get the Hour and minute as string :

Time today = new Time(Time.getCurrentTimezone());
today.setToNow();

int hour = today.hour;
String hh = Integer.toString(hour);

int minute = today.minute;
String mm = ":" + Integer.toString(minute);

and then i have showed those two strings inside of two image views with bitmap:

        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);

        views.setImageViewBitmap(R.id.imageView1, getFontBitmap(context, hh, Color.WHITE, 70));

        views.setImageViewBitmap(R.id.imageView2, getFontBitmap1(context, mm, Color.WHITE, 70));

        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
} 

and this my receiver in manifest:

      <receiver android:name="widget">
   <intent-filter>
       <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
   </intent-filter>
   <meta-data android:name="android.appwidget.provider"
       android:resource="@xml/widget"/>

and here is my widget.xml in res/xml:

<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
    android:minWidth="288dp" 
    android:minHeight="144dp" 
    android:updatePeriodMillis="10000" 
    android:initialLayout="@layout/widget_layout">
</appwidget-provider>

so any help?

Thanks in advance

هل كانت مفيدة؟

المحلول

Just in case someone stumbles through this problem.

I believe the problem lies within the android:updatePeriodMillis. The minimum time allowed for the update is 30 minutes, if you require a shorter time period, you'll have to to set the time to "0" and then implement your own method of updating the widget, like using a repeated AlarmManager. However, be aware that frequent updates on the AppWidget might drain the battery life, so use it with caution, or at least ensure that the updates occur only while the device is not in sleep mode.

http://developer.android.com/guide/topics/appwidgets/index.html#MetaData

It seems in case of less than 30 minutes time period being set, it will do the first update (Which is called by default in case no Configuration Activity is being provided) but will request the next update after 30 minutes which is the minimum time.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top