我創建了一個通知applcation.Notification通知。我想要通過單擊通知去新的活動。我不知道該怎麼做。請給我一個幫助。謝謝!Android通知
我有2個班的通知 1. Notification_2Activity
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DatePicker dp = (DatePicker) findViewById(R.id.datePicker1);
TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);
int month = dp.getMonth();
int year = dp.getYear();
int dayofmonth= dp.getDayOfMonth();
int hourofday=tp.getCurrentHour();
int minute=tp.getCurrentMinute();
EditText e = (EditText) findViewById(R.id.editText1);
e.setText("montho="+(month+1)+" year="+year+" day="+dayofmonth+" hour"+hourofday+" minute="+minute);
Calendar cal = Calendar.getInstance(); //for using this you need to import java.util.Calendar;
// add minutes to the calendar object
cal.set(Calendar.MONTH,month);
cal.set(Calendar.YEAR,year);
cal.set(Calendar.DAY_OF_MONTH, dayofmonth);
cal.set(Calendar.HOUR_OF_DAY, hourofday);
cal.set(Calendar.MINUTE, minute);
Intent alarmintent = new Intent(getApplicationContext(), AlarmReceiver.class);
alarmintent.putExtra("title","Title of our Notification");
alarmintent.putExtra("note","Description of our Notification");
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);
這裏是我的第二類 Alarmreceiver.java
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
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, NotifyMessage.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);
}
我在哪裏添加此代碼? – Lahi2010 2012-04-16 09:18:18
加入我們的報警接收器活動 – KMI 2012-04-16 09:21:06
謝謝我得到了! – Lahi2010 2012-04-16 09:23:09