Azure / Azure/azure-notificationhubs-java-backend
Unable to successfully send android notification
- Lenguaje dominante
- Java
- Estrellas
- 35
- Forks
- 52
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
```c#
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 outconme = _notificationHub.SendFcmNativeNotificationAsync(BODY, "$InstallationId:{" + installationId + "}", CancellationToken.None);
await _notificationHub.DeleteInstallationAsync(installation.InstallationId);
```
NOT Working Java code
```java
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);
```
Guía de contribución
Línea de trabajo
Empieza comparando los fragmentos de Java y .NET, especialmente el ID de instalación, la plataforma y el selector de notificaciones utilizados en cada flujo. Sigue las llamadas del Java SDK para crear, enviar y eliminar la instalación; después, verifica el resultado y el comportamiento de entrega comparándolos con el ejemplo funcional de .NET. El trabajo se considera terminado cuando el flujo de Java envía correctamente la notificación al dispositivo Android registrado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- azure, java
- Área
- api, backend, mobile
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100