Skip to content

Unable to successfully send android notification #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Prev-I opened this issue Apr 26, 2023 · 2 comments
Open

Unable to successfully send android notification #167

Prev-I opened this issue Apr 26, 2023 · 2 comments

Comments

@Prev-I
Copy link

Prev-I commented Apr 26, 2023

We are trying to send a push notification on android device using GCM/FCM with the latest Notification-Hubs-java-sdk version (1.0.4).

We wrote the same code in dotnet and we can successully send a notification. Using the java sdk we see that the notification are received on notification hub but they never pass to successfull status on dashboard.

Watching the situation on firebase with the java code none of the notification are delivered to the account. Instead, the same hub, used by dotnet delivered notification successfully.

Working Dotnet code

String TOKEN = "XXXXX";
String CONNECTION_STRING = "Endpoint=sb://joinon-notificationhub-dev.servicebus.windows.net/;SharedAccessKeyName=joinon-notificationhub-dev;SharedAccessKey=YYYYY";
String HUB_NAME = "joinon-notificationhub-dev";
String BODY = "{\"data\":{\"title\": \"maco: TESTME\",\"body\" : \"Nessuna perdita d’acqua nella stanza sensori.\", \"icon\": \"notification/water_off\"}, \"notification\":{\"title\": \"maco: Nessun allarme perdita acqua rilevato\",\"body\" : \"Nessuna perdita d’acqua nella stanza sensori.\"}}";

String installationId = "installationIdTest";
NotificationHubClient _notificationHub = NotificationHubClient.CreateClientFromConnectionString(CONNECTION_STRING, HUB_NAME);

Installation installation = new Installation();
installation.InstallationId = installationId;
installation.PushChannel = TOKEN;
installation.Platform = NotificationPlatform.Fcm;
await _notificationHub.CreateOrUpdateInstallationAsync(installation);

Task<NotificationOutcome> outconme = _notificationHub.SendFcmNativeNotificationAsync(BODY, "$InstallationId:{" + installationId + "}", CancellationToken.None);

await _notificationHub.DeleteInstallationAsync(installation.InstallationId);

NOT Working Java code

String TOKEN = "XXXX";
String CONNECTION_STRING = "Endpoint=sb://joinon-notificationhub-dev.servicebus.windows.net/;SharedAccessKeyName=joinon-notificationhub-dev;SharedAccessKey=YYYYY";
String HUB_NAME = "joinon-notificationhub-dev";
String BODY = "{\"data\":{\"title\": \"maco: TESTME\",\"body\" : \"Nessuna perdita d’acqua nella stanza sensori.\", \"icon\": \"notification/water_off\"}, \"notification\":{\"title\": \"maco: Nessun allarme perdita acqua rilevato\",\"body\" : \"Nessuna perdita d’acqua nella stanza sensori.\"}}";

NotificationHub notificationHub = new NotificationHub(CONNECTION_STRING, HUB_NAME);

String installationId = "installationIdTest";
Installation installation = new Installation(UUID.randomUUID().toString(), NotificationPlatform.Gcm, TOKEN);

notificationHub.createOrUpdateInstallation(installation);
Notification n = Notification.createFcmNotification(BODY);
NotificationOutcome outcome = notificationHub.sendNotification(n, "$InstallationId:{" + installationId + "}");

notificationHub.deleteInstallation(installationId);
@pratikiitdh
Copy link

Even I am facing the same issue. I am using fcmV1 whose support was recently built in this sdk. However facing the same problem. Can see that incoming notification count is increasing on azure hub, however not of them actually reach the device.
Also tried using the test send option from portal, it works and notificaitions also work

@toppev
Copy link

toppev commented Nov 1, 2024

Also facing the same issue, any solutions? "Test Send" works but not via SDK. notificationId is null but trackingId exists in the outcome

edit: Notification.createFcmV1Notification("{ \"message\": { \"notification\": { \"body\" : \"hello\"} } }") worked. The issue seems to be with my template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants