我正在使用闹钟管理器获取本地通知是我的代码,它运行正常,所有闹钟和通知都在正确的时间到来。但我希望当我点击通知时,它应该转到我的应用中的课程Act_Remainder
。
如何解决这个问题?
Intent intent1 = newIntent(this.getApplicationContext(), Act_Remainder.class);
if(intent!=null){
userID = intent.getStringExtra("UserID");
userID1 = intent.getStringExtra("UserID1");
ID = intent.getIntExtra("ID", 0);
}
Notification notification = new Notification(R.drawable.ioc_icon,
userID1, System.currentTimeMillis());
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_ONE_SHOT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
答案 0 :(得分:1)
或者只是使用这个......
public void onStart(Intent intent,int startId){ super.onStart(intent,startId);
mManager = (NotificationManager) this.getApplicationContext()
.getSystemService( this.getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(this.getApplicationContext(),Act_DashBord.class);
Notification notification = new Notification(R.drawable.applogo_57x57,
"Muslim Companion", System.currentTimeMillis());
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
this.getApplicationContext(), 0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
int id = 0;
if (intent != null) {
String message = intent.getStringExtra("Message");
id = intent.getIntExtra("Id", 0);
}
notification.setLatestEventInfo(this.getApplicationContext(),
"Muslim Companion", message, pendingNotificationIntent);
long count = System.currentTimeMillis();
mManager.notify(Integer.valueOf(id), notification);
mManager.cancel(Integer.valueOf(id));
}