3

我正在开发一个小应用程序,我希望后台服务发送通知,当用户单击通知时,它必须启动适当的活动。我在此处发布通知的代码,我的问题是通知显示在状态栏上,但是当我单击它时,它不会启动活动。有人可以建议我哪里出错了。请帮忙。

NotificationManager notificationManager = (NotificationManager) 
        getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
        "A New Message!", System.currentTimeMillis());
Intent notificationIntent = new Intent(NotificationService.this,
        com.jeris.android.MetroActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent
        .getService(NotificationService.this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(NotificationService.this, "Bullion",
        "Rates for "+ parsedDate+"has not been updated. Go to app to check rates",
        pendingIntent);
notificationManager.notify(11, notification);
4

1 回答 1

5

代替 PendingIntent.getService(NotificationService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

PendingIntent.getActivity(NotificationService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

注意getService被替换为getActivity

于 2012-06-18T11:03:46.273 回答