【问题标题】:Android : how to NOT bring the app to front when the user clicks on a button in the notification?Android:当用户单击通知中的按钮时,如何不将应用程序置于前面?
【发布时间】:2017-04-28 15:47:46
【问题描述】:

我有一个带有按钮的通知,当用户单击其中一个按钮时,这些按钮会修改通知界面。

通知界面更新正常,但...我的应用程序的主要活动也被带到了前面。

如何避免将应用置于最前面?

谢谢!!!

【问题讨论】:

  • 你能分享一些代码吗?
  • 您是如何收到通知的?是 Firebase 还是你自己生成的?如果你分享一些代码sn-p会很清楚。
  • 感谢您的回答。找到了解决方案!通知的意图必须触发服务而不是活动。

标签: java android android-intent push-notification notifications


【解决方案1】:

找到了解决办法!

通知的意图必须触发服务而不是活动。

Intent buttonsIntent = new Intent(this, NotificationManagementService.class);
        buttonsIntent.putExtra("do_action", action);
        contentView.setOnClickPendingIntent(R.id.notifButton, PendingIntent.getActivity(this, 0, buttonsIntent, PendingIntent.FLAG_UPDATE_CURRENT));
        notification.contentView = contentView;
  mNotificationManager.notify(1, notification);

【讨论】:

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