ステータスバーに日付をアイコン(毎日の画像、1、2、3、...)として表示するアプリを開発していますが、日付が変わったときにそれを感知できないという問題があります。日付の変更をキャッチしてステータスバーのアイコンを更新できる方法はありますか。
mNM =(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
int resId = getResources().getIdentifier("p_"+Day_Num, "drawable", getPackageName());
Notification notification = new Notification(resId, "", System.currentTimeMillis());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setImageViewResource(R.id.image, resId);
contentView.setTextViewText(R.id.title, Day);
contentView.setTextViewText(R.id.text, Date);
contentView.setOnClickPendingIntent(R.id.imageView1, PendingIntent.getActivity(this, 0, new Intent(this, Option.class),0));
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, Option.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.defaults = Notification.FLAG_NO_CLEAR;
mNM.notify(NOTIFICATION, notification);
サービス Calservice.java を使用する場合:
public void onCreate() {
//code to execute when the service is first created
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(ALARM_REFRESH_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
alarmReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
alarmCounted++;
Message msg = myHandler.obtainMessage(ALARM_CODE, intent);
myHandler.sendMessage(msg);
}
};
IntentFilter filter = new IntentFilter(ALARM_REFRESH_ACTION);
registerReceiver(alarmReceiver, filter);
mNM =(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
utils.getCurrentShamsidate();
startRepeating();
}
public void startRepeating() {
// We get value for repeating alarm
int startTime =1000;
long intervals =1000;
// We have to register to AlarmManager
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.MILLISECOND, startTime);
// We set a repeating alarm
alarmManager.setRepeating(AlarmManager.RTC, calendar
.getTimeInMillis(), intervals, pendingIntent);
}
private void showNotification() {
mNM.cancelAll();
utils.getCurrentShamsidate();
int resId = getResources().getIdentifier("p_"+Day_Num, "drawable", getPackageName());
Notification notification = new Notification(resId, "", System.currentTimeMillis());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setImageViewResource(R.id.image, resId);
contentView.setTextViewText(R.id.title, Day);
contentView.setTextViewText(R.id.text, Date);
contentView.setOnClickPendingIntent(R.id.imageView1, PendingIntent.getActivity(this, 0, new Intent(this, Option.class),0));
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, Option.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
mNM.notify(NOTIFICATION, notification);
}
public void doscan() {
String Day = Day_Num;
utils.getCurrentShamsidate();
if(!Day_Num.equals(Day))
showNotification();
}