如何点击点击时发布通知的活动?

时间:2015-10-17 05:13:47

标签: android

我想打开发出通知的活动,如果用户点击它,则应将用户定向到该活动。通知应该消失。

2 个答案:

答案 0 :(得分:3)

在android

中使用此方法进行开放活动
   // Notification Method
private void Notification(String notificationTitle,
        String notificationMessage) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    android.app.Notification notification = new android.app.Notification(
            R.drawable.ic_launcher, "Message from Binesh Kumar! (Android Developer)",
            System.currentTimeMillis());

    Intent notificationIntent = new Intent(this, AndroidNotifications.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);

    notification.setLatestEventInfo(AndroidNotifications.this,
            notificationTitle, notificationMessage, pendingIntent);
    notificationManager.notify(10001, notification);
}

答案 1 :(得分:1)

<强> 1 即可。创建类似

的任何通知
NotificationCompat.Builder mBuilder =

    new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle("My notification")
    .setContentText("Hello World!");

2。现在,如果您要关联任何活动ResultActivity,请创建PendingIntent

Intent resultIntent = new Intent(this, ResultActivity.class);

PendingIntent resultPendingIntent =

    PendingIntent.getActivity(
    this,
    0,
    resultIntent,
    PendingIntent.FLAG_UPDATE_CURRENT
);

3:将待处理意图设置为通知构建器

mBuilder.setContentIntent(resultPendingIntent);