【问题标题】:How to display the app name in a local notification in Xamarin?如何在 Xamarin 的本地通知中显示应用名称?
【发布时间】:2018-07-20 10:27:09
【问题描述】:

我有一个带有local notification 的应用程序。问题是它显示了来自 Visual Studio 的“项目名称”(见截图)。我希望应用程序显示我可以指定的内容(应用程序名称)。

[

您在上面看到的构建通知的代码是:

PendingIntent resultPendingIntent = stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

// Build the notification:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
    .SetAutoCancel(true)
    .SetContentIntent(resultPendingIntent)
    .SetContentTitle("Button Clicked")
    .SetNumber(count)
    .SetSmallIcon(Resource.Drawable.ic_stat_button_click)
    .SetContentText(String.Format("The button has been clicked {0} times.", count));

// Finally, publish the notification:
NotificationManager notificationManager = (NotificationManager)GetSystemServiceContext.NotificationService);
notificationManager.Notify(ButtonClickNotificationId, builder.Build());

我正在使用 Android 7.0 进行测试,本地通知文档似乎没有显示任何关于显示通知的“新”方式的任何内容。不过我可以更改小图标。

我在 Xamarin 论坛或 Google 上找不到有关该问题的任何信息。我真的怀疑人们想在那里看到 Visual Studio 的项目名称。

我什至下载了local notification sample project,它显示了项目名称。

这是一个限制还是我错过了什么?在我看来,这件事太重要了,不能成为限制。

【问题讨论】:

    标签: c# xamarin xamarin.forms notifications xamarin.android


    【解决方案1】:

    您在AndroidManifest.xml 中查找Android 应用程序的android:label,在Xamarin.Android 项目设置中称为“应用程序名称”。

    AndroidManifest.xml

    ~~~~
    <application android:label="StackoverFlow" ~~~
    ~~~~
    

    输出:

    注意:除了直接在AndroidManifest.xml中设置,您还可以使用汇编级别ApplicationAttribute:

    [assembly: Application(Icon = "@drawable/Icon", Label = "StackOverflow")]
    

    仅供参考:Xamarin 的项目模板在 AssemblyInfo.cs 中使用图标参数创建此应用程序属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-30
      • 1970-01-01
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      • 2018-11-11
      • 2022-08-16
      相关资源
      最近更新 更多