0
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);

我仍在寻找成功运行通知的解决方案!!!!我显示消息,但在通知用户后我试图触发的活动不起作用....我只需要一个通知演示,它会给出结果,我会完成其余的。再次感谢。我正在寻找您的友好回复..

4

1 回答 1

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());
于 2013-03-01T07:39:21.593 回答