android - 本地通知实现
问题描述
我正在尝试使用 Xamarin.Forms 为我的 android 应用程序实现本地通知(带有点击事件和 HeadUP 通知)。我已经关注了本地通知的Microsoft 文档,但我不知道如何实现这一点。任何人都可以为此分享任何工作示例。
谢谢你。
解决方案
从Android官方文档中,有两种设置重要性级别的方法。
第一个解决方案:(不工作)
如果通知的优先级标记为高、最大或全屏,则会收到提示通知。
可能触发平视通知的条件示例包括: 通知具有高优先级并使用铃声或振动。使用物理设备尝试如下:
builder.SetVibrate(new long[0]);
builder.SetPriority((int)NotificationPriority.High);
这是关于单挑通知的类似讨论。
不幸的是,上述解决方案不起作用。
第二种解决方案:(工作)
Xamarin Android 中的正确方法是设置Channel的属性。如果频道是由创建的NotificationImportance.High
,则可以显示抬头。您可以参考这个官方示例。并修改您的CreateNotificationChannel
方法如下:
void CreateNotificationChannel()
{
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
// Notification channels are new in API 26 (and not a part of the
// support library). There is no need to create a notification
// channel on older versions of Android.
return;
}
var name = Resources.GetString(Resource.String.channel_name);
var description = GetString(Resource.String.channel_description);
//Replace follow NotificationImportance.Default to NotificationImportance.High
var channel = new NotificationChannel(CHANNEL_ID, name, NotificationImportance.High)
{
Description = description
};
var notificationManager = (NotificationManager) GetSystemService(NotificationService);
notificationManager.CreateNotificationChannel(channel);
}
推荐阅读
- sql - Oracle SQL ROWNUM 和 NEXTVAL
- java - 通过引用传递与变量中的值与数组元素
- http - HTTP2 请求语法
- jquery - 更新对 Hangfire 仪表板的 jQuery 依赖
- android - 如何恢复来自应用程序外部的音乐?
- jquery - ie8不支持HTTPS协议的API接口吗?
- javascript - jQuery 等待两个触发器
- xamarin.ios - Xamarin.iOS MT2002 无法解析 Xamarin 11.9.1 上的 BindingImplAttribute
- visual-studio-2015 - 用vs2015编译mfc程序出错
- oculus - Oculus Go 开发者模式 - 已成功安装 apk,但未在 Oculus 中显示