Hello.
Unfortunately couldn't find information about this question so I'll just ask.
Is it even possible to read foreing push notifications within Xamarin app. For example notifications from Google Pay?
And how to achieve that?
Thank you.
Hello.
Unfortunately couldn't find information about this question so I'll just ask.
Is it even possible to read foreing push notifications within Xamarin app. For example notifications from Google Pay?
And how to achieve that?
Thank you.
Do you want to achieve the firebase notification in xamarin.android? If so, please check this path: https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm, If not, could you give me some details about the foreing push notifications.
I have Xamarin App that reads financial SMS. I'd like to make it read push notifications from google pay and banks' apps as well.
Hello,
Welcome to our Microsoft Q&A platform!
I have Xamarin App that reads financial SMS. I'd like to make it read push notifications from google pay and banks' apps as well.
For Android, we can use NotificationListenerService to achieve it like following code. For iOS, it cannot be achieved.
1.Create a service to extend the NotificationListenerService. If the notification is coming, you can get the content from notification from OnNotificationPosted method.
[Service(Label = "ServiceName", Permission = "android.permission.BIND_NOTIFICATION_LISTENER_SERVICE")]
[IntentFilter(new[] { "android.service.notification.NotificationListenerService" })]
public class NLService : NotificationListenerService
{
public override void OnCreate()
{
base.OnCreate();
Log.Info("start running", "Servico Criado");
}
public override void OnDestroy()
{
base.OnDestroy();
}
public override IBinder OnBind(Intent intent)
{
return base.OnBind(intent);
}
public override bool OnUnbind(Intent intent)
{
return base.OnUnbind(intent);
}
public override void OnNotificationPosted(StatusBarNotification sbn)
{
var notification= sbn.Notification;
Bundle extras = notification.Extras;
if (extras != null)
{
// Get the title from notification
string title = extras.GetString(Notification.ExtraText, "");
// Get the content from notification
string content = extras.GetString(Notification.ExtraText, "");
Console.WriteLine("============" + content + "======================");
}
base.OnNotificationPosted(sbn);
}
public override void OnNotificationRemoved(StatusBarNotification sbn)
{
base.OnNotificationRemoved(sbn);
}
}
2.Then use it with Intent to open system page, then enable it for your applicaion.
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
StartActivity(intent);

Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Thank you, Leon Lu. I will try to adapt this solution. Can it be run as foreground service?
Tried but no luck.
Foreground service is started but OnNotificationPosted not fired when I send messages to test device. :(
I did not test it in the foreground service, I run this code in Activity, it worked. It is a normal service (above code), android OS will close it when you application running in background after several minutes, because the Background Execution Limits in Android 8.0
So, it turns out that I can't rely on Activity and should consider only Foreground Service as relatively guaranteed method to catch all notifications. Or I am wrong?
8 people are following this question.