private void generateNotification() {
// TODO Auto-generated method stub
String notificationTicket=new Date(System.currentTimeMillis()).toLocaleString();
long when=System.currentTimeMillis();
Notification myNotification=new Notification(R.drawable.ic_launcher, notificationTicket, when);
Intent intent=new Intent(getApplicationContext(),MyNewActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent=PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
myNotification.setLatestEventInfo(getApplicationContext(), null, "Hi some package Added", pendingIntent);
notificationManager.notify(0, myNotification);
}
我使用了一个按钮来触发通知,它显示在我的ActionBar上,但是它没有加载我想要的新Activity。我之前已经定义了我的NotificationManager。 还有一个取消通知按钮,但它不值得作为通知火灾仅“几秒钟”。在此先感谢。
startButton=(Button)findViewById(R.id.button1);
startButton.setOnClickListener(this);
stopButton=(Button)findViewById(R.id.button2);
stopButton.setOnClickListener(this);
notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
我仍在寻找成功运行通知的解决方案! 我显示消息,但是在通知用户后我要触发的活动不起作用.... 我只需要一个通知的演示程序给出结果,我将完成剩下的工作。再次感谢。我正在寻找你的回复..
答案 0 :(得分:0)
试试这个..!
long timestamp=System.currentTimeMillis();
int i=(int) timestamp;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Title")
.setAutoCancel(true);;
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MyNewActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent pendingIntent =stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pendingIntent);
mNotificationManager =(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(i, mBuilder.build());