繁体   English   中英

单击该活动如何打开启动通知的活动?

[英]How to open the activity that launched a notification when clicked on it?

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

在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 创建类似的任何通知

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM