【问题标题】:Xamarin how can i get all system notification?Xamarin 如何获取所有系统通知?
【发布时间】:2018-09-21 20:24:46
【问题描述】:

我是新来的。当我按下 FAT 按钮时,我正在开发一个使用谷歌地图的应用程序。目前,谷歌地图没有显示您何时完成导航,因此为了能够返回我的应用程序,我正试图以某种方式做到这一点。 我在想,当您处于导航模式时,谷歌地图会向您显示通知。在导航完成之前,它不会被删除。我想得到这个通知,当我的按钮被按下时,检查通知是否处于活动状态。如果它不活跃,那么我可以返回我的应用程序。 这是我一直在尝试做的:

 NotificationManager notificationManager =
          GetSystemService(Context.NotificationService) as NotificationManager;

                            StatusBarNotification[] nnn2 = notificationManager.GetActiveNotifications();

当我检查 nnn2 以查看哪些服务处于活动状态时,它什么都没有。我不知道我是否需要在清单中添加一些权限,或者我完全错了。

【问题讨论】:

  • getActiveNotifications 仅返回您的应用(此方法的调用者)仍可供用户使用的通知。

标签: android google-maps xamarin xamarin.android


【解决方案1】:

这是可能的,可以这样做:

对于低于 API 11 的级别:

 Notification notify = new Notification();
            notify.Defaults = NotificationDefaults.Sound;
            notify.Defaults = NotificationDefaults.Vibrate;
            notify.Flags = NotificationFlags.NoClear;// Cruicial line of code 

对于 API 11 及更高版本:

 Notification notify = new Notification();
            notify.Defaults = NotificationDefaults.Sound;
            notify.Defaults = NotificationDefaults.Vibrate;
            notify.Flags = NotificationFlags.NoClear;

 NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
             .SetSmallIcon(Resource.Drawable.Icon)
             .SetContentTitle(messageTitle)
             .SetContentText(messageBody)
             .SetOngoing(true)//Important line of code
             .SetContentIntent(pendingIntent);
 NotificationManagerCompat notificationManager = NotificationManagerCompat.From(this);
            notificationManager.Notify(0, notificationBuilder.Build());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-20
    • 2016-10-16
    • 2017-04-04
    • 1970-01-01
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多