当我在Android中显示通知时,通知会被放置在Android的通知区域中。当我下拉时我可以看到它,但它不会像我看过许多应用程序那样自动下拉。如何强制通知下拉?我的应用程序打开时这可能吗?如果我的应用关闭或不全屏,它是否只会下拉?
我正在使用Xamarin,这是我的代码(基本上是从Google自己的例子中复制的):
更新现在,代码段工作正常,并显示“抬头”通知。
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());
答案 0 :(得分:3)
我认为你想要的是一个“单挑”通知: http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Heads-up
可能触发抬头通知的条件示例包括:
用户的活动处于全屏模式(该应用使用fullScreenIntent),
通知具有高优先级并使用铃声或振动