Riskhan
Riskhan

Reputation: 4472

need help on android widget

I am newbie in android programming. I like to create a widget to update network status such as signal level, operator details. Can i update these data on an interval of a second. It is possible in widget. If yes kindly provide a solution to do it.
thanks

Upvotes: 1

Views: 78

Answers (1)

Leon Lucardie
Leon Lucardie

Reputation: 9730

You can't do this natively because android:updatePeriodMillis is restricted to a minimum period of 30 minutes.

You can bypass this limit by adding a service that will update your widget to the AlarmManager(which does support intervals less than 30 minutes):

final Intent _intent = new Intent(context, MyUpdateService.class);
final PendingIntent pending = PendingIntent.getService(context, 0, _intent, 0);
final AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarm.cancel(pending);
long interval = 60000;
alarm.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),interval, pending)

Upvotes: 1

Related Questions