I have created a xamarin app, and I want to edit the text of a push notification text before it gets displayed to the user.
I am using a Notification Extenstion Service and also OneSingal library to get the notifications.
using System;
using Android.App;
using Android.Content;
using Android.Preferences;
using Android.Support.V4.App;
using Com.OneSignal.Android;
using MyApp.Shared.Utility;
namespace MyApp.Droid
{
[Service(Permission = "android.permission.BIND_JOB_SERVICE")]
[IntentFilter(new String[] { "com.onesignal.NotificationExtender" })]
public class CustomNotificationExtenderService : NotificationExtenderService
{
private OSNotificationReceivedResult _result;
private NotificationManager notifyManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
private NotificationCompat.Builder builder = new NotificationCompat.Builder(Application.Context, "1");
protected override void OnHandleIntent(Intent intent){ }
protected override bool OnNotificationProcessing(OSNotificationReceivedResult p0)
{
_result = p0;
var body = "New Encrypted Message";
NotificationCompat.Builder builder = new NotificationCompat.Builder(Application.Context, "1");
builder.SetSmallIcon(Resource.Drawable.Logo);
builder.SetStyle(new NotificationCompat.BigTextStyle().BigText(body));
builder.SetContentTitle("New Message");
builder.SetContentText(body);
// Build the notification and display it
notifyManager.Notify(1, builder.Build());
return false;
}
}
}
Please note that in my sample code above I have omitted the logic for the creation of text that goes in the notification banner. I was expecting to see a push Notification with a text 'New Encrypted Message'. But it shows the actual message that sends from the server.
I would appreciate your help