【问题标题】:Broadcast Receiver and widget timezone广播接收器和小部件时区
【发布时间】:2012-03-05 12:44:14
【问题描述】:

我使用广播接收器、WidgetProvider 和配置活动。活动在创建小部件期间开始。小部件每 20 秒更新一次。

  private PendingIntent service = null; 
   Intent intent = new Intent(context, AlarmReceiver.class);
       if (service == null) {
        service = PendingIntent.getBroadcast(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
    }
        m.setRepeating(AlarmManager.RTC, TIME.getTime().getTime(), 1000 * 20,
            service);

我想在手机上更改时间或时区时更新小部件。当我提前更改时间时,小部件会更新。但是当我把时间改回来时,什么也没有发生。 我已经添加到清单中了

        <receiver android:name=".AlarmReceiver" >
        <intent-filter>
            <action android:name="android.intent.ACTION_TIMEZONE_CHANGED" />
            <action android:name="android.intent.ACTION_TIME" />
        </intent-filter>
    </receiver>

在广播接收器中,我正在更新小部件。

【问题讨论】:

    标签: android android-widget broadcastreceiver alarmmanager


    【解决方案1】:

    请参考 http://developer.android.com/reference/android/content/Intent.html#ACTION_TIMEZONE_CHANGED

    他们应该是

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

    【讨论】: