Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the app name in a local notification in Xamarin?

I have an app with a local notification. The problem is that it displays the "Project name" that comes from Visual Studio (see the screenshot). I would like the app to display something I can specify (the application name).

[2]

The code to build the notification you see above is :

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());

I'm testing with Android 7.0 and it seems like the local notification documentation does not show anything about this "new" way of displaying a notification. I am able to change the small icon though.

I could not find anything on Xamarin forums or Google about that problem. I truly doubt people want to see the Visual Studio's project name there.

I even downloaded the local notification sample project and it shows the project name.

Is it a limitation or am I missing something ? It seems to me like something too important to be a limitation.

like image 749
Maxime Avatar asked Feb 09 '18 15:02

Maxime


People also ask

How do I ask for location permission in xamarin?

To request a permission from the users, use the RequestAsync method along with the specific permission to request. If the user previously granted permission and hasn't revoked it, then this method will return Granted immediately and not display a dialog. var status = await Permissions.

What is local notification in Android?

Local notifications are scheduled by an app and delivered on the same device. They are suited for apps with time-based behaviors, such as calendar events. When you run your app on a device with Android OS 8.0 or above, Kony uses default channels that are mentioned in the localnotificationconfig.


1 Answers

You are looking for the Android application's android:label in the AndroidManifest.xml, known as the "Application name" in the Xamarin.Android project settings.

enter image description here

AndroidManifest.xml

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

Output:

enter image description here

Note: Instead of setting this directly in the AndroidManifest.xml, you can also use an assembly level ApplicationAttribute:

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

FYI: Xamarin's project template creates this Application attribute in AssemblyInfo.cs with an Icon parameter

like image 53
SushiHangover Avatar answered Oct 10 '22 01:10

SushiHangover