c# - Xamarin Android 无法接收举手通知(横幅通知)
问题描述
我正在我的应用程序上构建通知系统,但问题出在 Andorid Os 中,尤其是华为 p20 lite 我无法在屏幕顶部获得通知横幅
我尝试了很多教程
( https://snag.gy/xy2ImQ.jpg ) 图片 我希望这是真的或激活
Xamarin:
{
var intent = new Intent(this, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
intent.PutExtra("SomeSpecialKey", "some special value");
foreach (var key in data.Keys)
{
intent.PutExtra(key, data[key]);
}
var pendingIntent = PendingIntent.GetActivity(this,
MainActivity.NOTIFICATION_ID,
intent,
PendingIntentFlags.OneShot);
var notificationBuilder = new NotificationCompat.Builder(this, MainActivity.CHANNEL_ID)
.SetSmallIcon(Resource.Drawable.ic_stat_ic_notification)
.SetContentTitle(title)
.SetContentText(messageBody)
.SetPriority(5)
.SetDefaults(1)
.SetVibrate(new long[0])
.SetContentIntent(pendingIntent);
/* NotificationChannel channel = new NotificationChannel(
MainActivity.CHANNEL_ID,
new Java.Lang.String("Channel"),
NotificationImportance.High
); */
var notificationManager = NotificationManagerCompat.From(this);
notificationManager.Notify(MainActivity.NOTIFICATION_ID, notificationBuilder.Build());
}
本地服务器:
{"to":"MYTOKEN","notification":{"title":"Working Good","body":"Okok" ,"sound": "default",
"icon": "icon_desc"},"priority":"high",
}
解决方案
我发现我的解决方案我创建了自定义频道
internal static readonly string CHANNEL_ID = "test";
我确实直接从 JSON Payload 文件设置了属性
{
"to": "fOBdGjbftTI:APA91bEV1G39J3sF-CBQMANdlW7ely-XGC8zQ9Fp00H31iHFsmxB5hcgFCMr8-Plh9w4bDHO9eDQ5Fr_SCbYjNJ93iaFvh-zcUe_e1sAKHmRo5u73vGMuGovmfvUuTIuak1xcoRTrOtQ",
"notification":{
"title":"New Notification!",
"body":"Test",
"android_channel_id":"test"
},
"priority":"High",
"android": {
"notification": {
"sound": "default"
}
}
}
推荐阅读
- java - 为什么 Java 的 InflaterInputStream (和其他类似的类)只能有条件地在其内部 Inflater 上调用 end
- c# - 如果路径等于文件夹名称,如何检查条件?
- ruby-on-rails - 模型键不传递给其他模型的形式
- api - 来自 PHP 的 Rest API
- html - 获取testcafe菜单中所有元素的文本
- javascript - 在动作分派时向对象数组中的每个对象添加键属性
- python - 代码停止并且不报告异常(使用“请求”)
- php - 有没有办法在 Magento 2.3 中通过声明性模式创建的表中播种数据?
- c++ - 如果操作系统不清除内存泄漏,程序完成后是否会持续存在?
- django - ModuleNotFoundError:Django 中没有名为“AppName”的模块