如何在Xamarin的本地通知中显示应用名称?

时间:2018-02-09 15:46:17

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

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

[2]

构建上述通知的代码是:

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进行测试,看起来本地通知文档似乎没有显示任何有关此内容的信息" new"显示通知的方式。我可以改变小图标。

我在Xamarin论坛或Google上找不到任何关于该问题的内容。我真的怀疑人们希望在那里看到Visual Studio的项目名称。

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

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

1 个答案:

答案 0 :(得分:3)

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

enter image description here

的AndroidManifest.xml

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

输出:

enter image description here

注意:您可以使用汇编级别AndroidManifest.xml代替直接在ApplicationAttribute中设置此内容:

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

仅供参考:Xamarin的项目模板在AssemblyInfo.cs中使用Icon参数创建此Application属性