0
我正在開發中的Android 2.1 我想設置多個通知警報,但在我的計劃任務管理器時,第二通知被顯示前一個被清除.plz幫助我,以顯示所有通知的間隔2分鐘後,說想..as完整... 我的代碼 1)主要活動多個通知
public class AlarmActivity extends Activity {
private static final String TAG = "SomeApp ";
protected Toast mToast;
@SuppressWarnings("unused")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Calendar cal = Calendar.getInstance(); // for using this you need to
// import java.util.Calendar;
// add minutes to the calendar object
cal.set(Calendar.HOUR_OF_DAY, 12);
cal.set(Calendar.MINUTE, 15);
// cal.set(Calendar.DAY_OF_MONTH, 24);
// cal.set(Calendar.MONTH,10);
// cal.set(Calendar.YEAR, 2011);
// cal.set will set the alarm to trigger exactly at: 21:43, 5 May 2011
// if you want to trigger the alarm after let's say 5 minutes after is
// activated you need to put
Intent alarmintent = new Intent(getApplicationContext(),
AlarmReceiver.class);
alarmintent.putExtra("title", "Title of ");
alarmintent.putExtra("note", "Description of our Notification");
// HELLO_ID is a static variable that must be initialised at the
// BEGINNING OF CLASS with 1;
int HELLO_ID = 1;
PendingIntent sender = PendingIntent.getBroadcast(
getApplicationContext(), HELLO_ID, alarmintent,
PendingIntent.FLAG_UPDATE_CURRENT |
Intent.FILL_IN_DATA);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
Calendar cal1 = Calendar.getInstance(); // for using this you need to
cal1.set(Calendar.HOUR_OF_DAY, 12);
cal1.set(Calendar.MINUTE, 17);
// cal.set(Calendar.DAY_OF_MONTH, 24);
// cal.set(Calendar.MONTH,10);
// cal.set(Calendar.YEAR, 2011);
Intent alarmintent1 = new Intent(getApplicationContext(),
AlarmReceiver.class);
alarmintent1.putExtra("title", "Title 2 ");
alarmintent1.putExtra("note", "Description 2");
int HELLO_ID1 = 2;
PendingIntent sender1 = PendingIntent.getBroadcast(
getApplicationContext(), HELLO_ID1, alarmintent1,
PendingIntent.FLAG_UPDATE_CURRENT |
Intent.FILL_IN_DATA);
AlarmManager am1 = (AlarmManager) getSystemService(ALARM_SERVICE);
am1.set(AlarmManager.RTC_WAKEUP, cal1.getTimeInMillis(), sender1);
}
2)報警接收機類
public class AlarmReceiver extends BroadcastReceiver {
private static final String NotificationManager = null;
private static int NOTIFICATION_ID = 0;
@Override
public void onReceive(Context context, Intent intent) {
// NotificationManager mNotificationManager =
// (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager manger = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
"Combi Note", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context,
NOTIFICATION_ID, new Intent(context,
AlarmReceiver.class), 0);
Bundle extras = intent.getExtras();
String title = extras.getString("title");
// here we get the title and description of our Notification
//
String note = extras.getString("note");
notification.setLatestEventInfo(context, note, title, contentIntent);
notification.flags = Notification.FLAG_INSISTENT;
notification.defaults |= Notification.DEFAULT_SOUND;
// here we set the default sound for our
// notification
// The PendingIntent to launch our activity if the user selects this
// notification
manger.notify(NOTIFICATION_ID, notification);
}
};
謝謝@gwa ....它的作品,但是當我按下清除選項卡所有notificatins得到清除..isit任何方式來清除通知,我widh並保持oters後來如果我很忙...... –
沒問題prakash_d22!您可以與FLAG_NO_CLEAR(notification.flags | = Notification.FLAG_NO_CLEAR;)標誌他們,但那麼你必須明確的是,你點擊明確使用mNotificationManager.cancel(MY_NOTIFICATION_ID)的通知;在你的土地上的代碼... – gwa
沒有得到you..plzü可以在我的代碼編輯和repaste它.... –