我有一个Android应用程序,有一个服务女巫基于一些时间计算发出警报.
问题是当时区发生变化时(即:对于位于法国并且从UTC + 1变为UTC + 2的用户).应用程序未收到有关此更改的通知,因此会立即触发警报.
我已经检查了android TimeZone API,并且知道有一些方法可以提供帮助,例如:
是否有可能知道何时会发生变化,以便在我的计算算法中考虑它?
顺便说一句:我已经从Stackoverflow检查了很多博客和Q/A,但没有帮助:(
编辑(清单文件和接收器类):
这是我的清单:
<receiver android:name=".receiver.NotificationReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
接收者类:
public class NotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
WakeLock.acquire(context);
Intent service = new Intent(context, NotificationService.class);
service.putExtras(intent);
context.startService(service);
// Timezone or time change
if (intent.getAction() != null
&& (intent.getAction().equals(Intent.ACTION_TIME_CHANGED)
|| intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)))
{
Intent i = new Intent(context, DialogPopUpTimeChange.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
Run Code Online (Sandbox Code Playgroud)