【问题标题】:How to detect if android app is open from a notification sent with PushSharp?如何从使用 PushSharp 发送的通知中检测 android 应用程序是否已打开?
【发布时间】:2015-04-28 09:12:18
【问题描述】:

所以我使用 PushSharp 将 c# 中的通知发送到我的 android 应用程序:

      var push = new PushBroker();
      push.RegisterGcmService(new GcmPushChannelSettings(androidKey) { });
      push.QueueNotification(
                new GcmNotification().ForDeviceRegistrationId(registrationId)
                    .WithJson("{\"alert\":\"" + PushMessageFormater.FormatMessage(ncRuleResult) + "\",\"badge\":7,\"sound\":\"sound.caf\"}"));

一切正常,通知已正确发送。

现在,我要做的就是从我的 MainActivity 检测当最终用户点击收到的通知时应用是否打开。

protected void onCreate(Bundle savedInstanceState) {
    registrationGetter = new RegistrationGetter(this);
    super.onCreate(savedInstanceState);
    Intent intent = getIntent() ;

   // How to check from here if the app is actually open further to a push tap.
}

我在 SO 中发现的只是我需要在 Intent 上放置一些额外的变量,但不幸的是,我找不到从 PushSharp 指定 Intent 的方法。

提前谢谢你。

【问题讨论】:

  • 您的设备是否收到推送通知??
  • 是的,我的设备正在接收推送通知。
  • 您必须从后台服务/广播接收器检查应用程序是否在后台或正在运行。如果您在接收器中接收通知时调用活动会使您的应用程序进入前台..
  • ty @user1992200,但我的问题不是很清楚。我已经添加了那部分:“现在,我要做的就是从我的 MainActivity 中检测当最终用户点击收到的通知时应用程序是否打开。”
  • 从主要活动中检查应用程序是否在前台是没有意义的..在点击通知时,您必须调用服务来检查应用程序是否是后台..

标签: android push-notification pushsharp


【解决方案1】:

在点击通知时更改待定意图以调用服务

PendingIntent pendingIntent = PendingIntent.getService(context, 579, intent,PendingIntent.FLAG_UPDATE_CURRENT);

refer here 检查应用程序是否在前台。您必须在点击收到的通知后从调用的服务中检查这一点。

【讨论】:

    猜你喜欢
    • 2013-04-29
    • 2015-11-17
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    • 2014-12-22
    • 1970-01-01
    • 2016-11-07
    相关资源
    最近更新 更多