9

毎日午後 12 時に通知を実行したいと考えています。when の値を時間に置き換えるにはどうすればよいですか?

NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification(R.drawable.icon,"Its Time to Eat",when);

Context context = GrubNOWActivity.this;
CharSequence title = "Its Time to Eat";
CharSequence details = "Click Here to Search for Restaurants";
Intent intent = new Intent(context,Search.class);
PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
notify.setLatestEventInfo(context, title, details, pending);
nm.notify(0,notify);
4

2 に答える 2

41

アラームマネージャを使用できます

Intent myIntent = new Intent(ThisApp.this , myService.class);     
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
pendingIntent = PendingIntent.getService(ThisApp.this, 0, myIntent, 0);

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 12);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 24*60*60*1000 , pendingIntent);  //set repeating every 24 hours

myServiceクラス内に通知を入れてください!

于 2011-11-26T20:48:00.667 に答える
1

このwhenパラメーターは、ステータス バーの通知を並べ替えるためのものです。目的の時間に通知を起動するようにアプリをコーディングする必要があります。

于 2011-11-26T20:05:55.897 に答える