【问题标题】:How to handle the case when click_action was sent to the previous version of the app where intent-filter was not added yet?当click_action被发送到应用程序的先前版本尚未添加意图过滤器的情况下如何处理?
【发布时间】:2017-01-11 18:11:02
【问题描述】:

你能帮我解决这个问题吗?

任务是开发将通过用户点击打开特定活动的推送通知。

我添加了意图过滤器并尝试使用 click_action 字段发送推送消息,一切都像魅力一样。

问题在于尚未添加 Intent-filter 的应用程序的先前版本。如果用户点击推送消息(在以前的应用程序版本的情况下),什么也不会发生。

在这种情况下怎么做更好?如何处理这种情况?

编辑:

所以问题是,在 click_action 字段中提到的特定屏幕并且缺乏必要的意图过滤器的情况下,我们如何才能具有默认行为(在最后一个屏幕上打开应用程序)?这与用户在清单文件中没有必要的意图过滤器的应用程序的早期版本的情况有关。

【问题讨论】:

  • 让用户更新到较新版本的应用以查看“新功能”。
  • 我不是在推动用户安装我的应用程序的新版本,我假设部分用户会使用旧版本。所以问题是,在缺少必要的意图过滤器的情况下,我们如何才能拥有默认行为(在最后一个屏幕上打开应用程序)

标签: android android-intent firebase push-notification firebase-cloud-messaging


【解决方案1】:

要对推送通知单击执行某些操作,我们需要编写代码来执行此类操作。在您的情况下,您想对旧的实时应用程序执行一些操作,在这种情况下您无能为力。

要执行某些操作,您可以在收到推送通知时调用此方法

private void sendNotification(String title, String messageBody) {
    Intent intent = new Intent(this, YourActivityName.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(title)
            .setContentText(messageBody)
            .setVibrate(new long[]{01})
            .setAutoCancel(true)
            .setContentIntent(pendingIntent);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        notificationBuilder.setSmallIcon(R.mipmap.notification);
    else
        notificationBuilder.setSmallIcon(R.mipmap.notification);


    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(1, notificationBuilder.build());
}

【讨论】:

  • 是的,这很清楚。但是如何向后兼容以前版本的应用程序,这是个问题。例如,对于以前的版本,我希望应用程序像通常在用户单击通常的推送通知时那样打开。
  • 感谢您的回答,但看起来您提供了显示本地通知的代码,对吗?但我说的是来自 FireBase 的通知。主要的问题是,如果之前版本的应用程序的清单文件中没有特定的意图,我们如何启动默认的 android.intent.action.MAIN 意图。所以,你认为这是不可能的,对吧?
猜你喜欢
  • 2020-05-31
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-20
  • 2011-01-13
  • 1970-01-01
  • 2014-07-15
相关资源
最近更新 更多