As of 1.6 (I believe) the updatePeriodMillis is forced to be at least 30
minutes.
-- Kostya
23.03.2011 19:07, Eduardo Yáñez Parareda пишет:
Hello, I'm developing my first widget so I've following Google
tutorials, but I don't get it works as I expect, it only calls
onUpdate when the widget is installed, but it isn't called again...
<code>
public class TestWidgetProvider extends AppWidgetProvider {
// Log tag
private static final String TAG = "TestWidgetProvider";
public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] widgetIds) {
Log.d(TAG, "onUpdate");
final int N = widgetIds.length;
// Por cada widget asociado al provider
for (int i = 0; i< N; i++) {
int widgetId = widgetIds[i];
updateWidget(context, appWidgetManager, widgetId);
}
}
static void updateWidget(Context context, AppWidgetManager
appWidgetManager, int widgetId) {
// Obtenemos las vistas del widget
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.gpro_widget_layout);
// Actualizamos el texto del widget
long time = System.currentTimeMillis();
String text = String.format("Hora: %d ms.", time);
views.setTextViewText(R.id.text, text);
// Actualizar el widget
appWidgetManager.updateAppWidget(widgetId, views);
}
}
</code>
XML config files:
/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.elpaso.android.gpro.widget" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"></uses-
permission>
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<receiver android:name="TestWidgetProvider">
<intent-filter>
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE" /
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/gpro_widget_provider_info" />
</receiver>
</application>
</manifest>
XML provider config:
xml/gpro_widget_provider.xml
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/
android"
android:minWidth="294dp"
android:minHeight="72dp"
android:updatePeriodMillis="5000"
android:initialLayout="@layout/gpro_widget_layout">
</appwidget-provider>
--
Kostya Vasilyev -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en