【问题标题】:User coming from a notification click来自通知点击的用户
【发布时间】:2018-11-25 15:01:41
【问题描述】:

如果用户来自通知点击,我想触发 Toast。

但我不知道如何知道用户是否来自通知点击。 知道我是这样设置通知的:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        int importance = NotificationManager.IMPORTANCE_DEFAULT;

        NotificationChannel channel =
                new NotificationChannel(notification_channel, notification_channel, importance);

        String description = "A channel which shows notifications about the app";
        channel.setDescription(description);

        channel.setLightColor(Color.MAGENTA);

        NotificationManager notificationManager = (NotificationManager) getApplicationContext().
                getSystemService(Context.NOTIFICATION_SERVICE);
        if (notificationManager != null) {
            notificationManager.createNotificationChannel(channel);
        }
    }

    String notificationTitle = "Title";
    String notificationText = "Notification Text";

    Intent intent_not = new Intent(getApplicationContext(), Home_Base.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent_not, FLAG_UPDATE_CURRENT);

    //build the notification
    NotificationCompat.Builder notificationBuilder =
            new NotificationCompat.Builder(getApplicationContext(), notification_channel)
                    .setSmallIcon(R.drawable.fiamma)
                    .setContentTitle(notificationTitle)
                    .setContentText(notificationText)
                    .setAutoCancel(true)
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                    .setContentIntent(pendingIntent);

    //trigger the notification
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(getApplicationContext());

    notificationManager.notify(123, notificationBuilder.build());

【问题讨论】:

    标签: java android push-notification notifications


    【解决方案1】:

    尝试使用 intent_not.setAction() 设置操作(例如 On_NOTIFICATION_CLICK)

    在 Home_Base 中使用 getIntent().getAction(),尝试从接收到的意图中获取操作。

    如果 Home_Base 中收到的操作是 On_NOTIFICATION_CLICK,则它是一个通知点击操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多