c# - 当我在 Android 中通知时,如何让我的通知下拉?

标签 c# android xamarin notifications

当我在 Android 中显示通知时,通知会放置在 Android 的通知区域中。当我下拉时我可以看到它,但它不会像我看到的许多应用程序那样自动下拉。如何强制通知下拉?我的应用程序打开时这可能吗?它是否仅在我的应用程序关闭或未全屏时才会下拉?

我正在使用 Xamarin,这是我的代码(基本上是从 Google 自己的示例中复制的):

更新 代码 fragment 现在可以工作并显示“提醒”通知。

string title = activity.Resources.GetString(Resource.String.Label_VideoSaved);
string text = string.Format(activity.Resources.GetString(Resource.String.Text_FileLocation), OutputFile);
Notification.Builder b = new Notification.Builder(activity);
b.SetSmallIcon(Resource.Drawable.Icon);
b.SetContentTitle(title);
b.SetContentText(text);
b.Extras.PutString("video", OutputFile);

// create a "heads up" notification with the following 2 lines:
b.SetPriority((int)Android.App.NotificationPriority.High);
b.SetVibrate(new long[0]);

Intent resultIntent = new Intent(activity, typeof(ViewVideoActivity));
TaskStackBuilder stackBuilder = TaskStackBuilder.Create(activity);
stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(ViewVideoActivity)));
stackBuilder.AddNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, PendingIntentFlags.UpdateCurrent);
b.SetContentIntent(resultPendingIntent);
NotificationManager notificationManager = (NotificationManager)activity.GetSystemService(Context.NotificationService);
notificationManager.Notify(0, b.Build());

最佳答案

我想你想要的是一个“提醒”通知: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Heads-up

Examples of conditions that may trigger heads-up notifications include:

The user's activity is in fullscreen mode (the app uses fullScreenIntent),

The notification has high priority and uses ringtones or vibrations

关于c# - 当我在 Android 中通知时,如何让我的通知下拉?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34009621/

相关文章:

c# - string.empty 和 string.isnullorempty

c# - 如何在 C# 中定义 "include"?

java - 选择单选按钮后启用复选框

xaml - 如何从 ViewModel 访问属性到 Xaml View 的 CodeBehind 内的 ButtonClickEvent?

c# - 是否可以用 C#(而不是 c\c++)编写 DirectShow 过滤器?

c# - 从 WPF 调用进程执行时间太长

android - 如何将png图像转换为矢量化图像?

android - 由于 JIT,BouncycaSTLe AES 256 多线程解密速度下降

android - Xamarin - Shell.Current.GoToAsync 和后退按钮

android - 如何添加“保存到手机谷歌”按钮并通过 xamarin 移动应用添加支付通行证