简体   繁体   中英

change widget update interval programatically android

I am working on Android widgets in my app. I have a Settings screen from where user can select content of widget and update interval of widget. There is AppWidgetProviderInfo API but don't know how to use it or is there any other way to change widget update interval? Please help me.

Thanks in advance.

is there any other way to change widget update interval?

Rather than using android:updatePeriodMillis , you will need to use AlarmManager to arrange to get control and update your app widget. You cannot modify android:updatePeriodMillis at runtime.

Add the following code in your AppWidgetProvider class in the onUpdate void.

int updateTime = 1800000; //30 min
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                               System.currentTimeMillis(),
                                updateTime,
                                pendingIntentAlarm);

您可以查看此malubu博客上提供的解决方案并查看来自malubu的github的源代码

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM