我想创建一个小部件,根据日期显示文本消息。我的问题是我不知道如何检测系统何时更改日期。
我的代码:
public class AlarmReceiver extends BroadcastReceiver {
MediaPlayer mp = null;// Here int m,n;
@Override public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_DATE_CHANGED)) { // new
MainActivity().setSunrise();
Toast.makeText(context, "deteced date change", Toast.LENGTH_SHORT).show();
}
public class AlarmReceiver extends BroadcastReceiver {
int m,n;
@Override public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_DATE_CHANGED)) {
Toast.makeText(context, "deteced date change", Toast.LENGTH_SHORT).show();
}
}
}