Based on Creating the Remote Notification Payload
it is possible to send App specific data to SNS for example acme2 in
{
"aps" : { "alert" : "Message received from Bob" },
"acme2" : [ "bang", "whiz" ]
}
How do set that data in Java using AmazonSNS
final PublishRequest publishRequest = new PublishRequest();
publishRequest
.withTargetArn(getDeviceEndpoint())
.withMessage(notification.getMessage())
.withSubject(notification.getTitle());
return snsClient.publish(publishRequest).getMessageId();
Turns out i need to set message type to json
publishRequest
.withTargetArn(userByUsername.get().getDeviceEndpoint())
.withMessage("{... json here ... }")
.withSubject(enclosedNotificiation.getTitle())
.withMessageStructure("json")
Related
This is the azure web page example in JAVA to get the message content from the azure service bus :
#FunctionName("sbprocessor")
public void serviceBusProcess(
#ServiceBusQueueTrigger(name = "msg",
queueName = "myqueuename",
connection = "myconnvarname") String message,
final ExecutionContext context
) {
context.getLogger().info(message);
}
This only return the content of the message. How is it possible to get the other fields that you can see in Service bus explorer : Label, Custom Properties and Broker Properties ?
You can retrieve message metadata by adding #BindingName("UserProperties") etc. annotation to method parameters like below for example. You can bind to any metadata of a message using binding expression. In this case below, it's "Properties" and "Label".
#FunctionName("sbprocessor")
public void serviceBusProcess(
#ServiceBusQueueTrigger(name = "msg", queueName = "myqueuename", connection = "myconnvarname")
String message,
final ExecutionContext context,
#BindingName("UserProperties")
Map<String, Object> properties,
#BindingName("Label")
String label) {
context.getLogger().info("Message received: " + message + " , properties: " + properties + " , label: " + label);
}
I used Service Bus Explorer as Message Sender to set metadata of the message as below and was able to see those in the consumer side using above code in "UserProperties" binding.
N.B. C# function SDK has a benefit here over Java. In C#, you can get the whole BrokeredMessage object which is easier to navigate for metadata directly. But unfortunately, that's not possible in Java SDK as of now where you have to bind separately.
I am currently working on an Android app and I added Firebase so I could get notifications.
Looking into this I bumped into onMessageReceived().
Does anyone know any real life examples of how this can be used? or what's the purpose?
Thanks for any help :)
whenever an app is in foreground/active the incoming notification goes into app which you can get from onMessageReceived() method, the notification will not be shown automatically, you will have to do it manually.
If the app is in background/inactive the incoming notification goes into the systems notification service which will show the notification automatically.
If you want to do both the task manually you have to send data while sending a fcm message.
or in in firebase functions you can do it like this
const payload = {
data: {
title: "title",
body: `body`,
icon: "default",
sound: "default"
}
};
const options = {
priority: "high",
timeToLive: 60 * 10
};
return admin.messaging().sendToTopic("notifyAll", payload, options)
.then((response) => {
console.log("Successfully sent message:", response);
return response;
})
.catch((error) => {
console.log("Error sending message:", error);
return error;
});
I have an Ionic app which receives push notifications via FCM. The problem is that when the app is not in the foreground and I click on the notification on the status bar, the app won't open (although the action from on('notification') is executed). This is my mobile app code:
this.pushNotifications.on('notification').subscribe((data: any) => {
if (data.additionalData.foreground) {
alert('Ai primit un mesaj nou');
}
this.events.publish("gotMessage");
});
Notice that this.events.publish("gotMessage"); is executed.
And this is how I send the notification through Java:
Map body = DataMap.map(
"registration_ids", tokens,
"data", DataMap.map(
"content-available", "1",
"title", "Fmcg Reporter",
"body", "Ai primit un mesaj nou",
"sound", "default"
),
"collapse_key", "FmcgReporter"
);
Map headers = DataMap.map(
"Authorization", "key=" + key,
"Content-Type", "application/json"
);
Strings.readMethodURL("POST", "https://fcm.googleapis.com/fcm/send", headers, Strings.toJSON(body));
Make sure when you send push notification using your server you specify "click_action". Below is a working example from my node.js server:
// method: "POST",
//url: "https://fcm.googleapis.com/fcm/send",
// get the key from Firebase console
headers: { Authorization: `key=${fcmServerKey}` },
json: {
"notification": {
"title": "Message title",
"body": "Message body",
"click_action": "URL to your app?"
},
// userData is where your client stored the FCM token for the given user
// it should be read from the database
"to": userData.fcmRegistrationKey
}
I am sending push notifications using UrbanAirship API using java.
Here is the doc: http://docs.urbanairship.com/api/
I want to send a push notifications with custom key/value. For example, I want send to following to Android/iOS device
name: "Jack"
String appKey = "appKey";
String appSecret = "appSecret";
// Setup an authenticated APIClient with your application key and
// application master secret.
APIClient apiClient = APIClient.newBuilder()
.setKey(appKey)
.setSecret(appSecret)
.build();
// Setup a push payload to send to the API with our handy builders
PushPayload payload = PushPayload.newBuilder()
.setAudience(Selectors.all())
.setNotification(Notifications.notification("UA Push"))
.setDeviceTypes(DeviceTypeData.of(DeviceType.IOS))
.build();
// Try and send, handle anything that comes up
try {
APIClientResponse<APIPushResponse> response = apiClient.push(payload);
logger.info("Sent a push message!");
}
// Non 200 responses throw an APIRequestException. Check the documentation
// to debug your request.
catch (APIRequestException ex){
logger.error("Non 200 request, checking error details and taking action");
}
// An underlying error occurred, most likely outside of the scope of the
// UA library, do some HTTP debugging
catch (IOException e){
logger.error("Broken pipe what?");
}
Here is the code reference for android - https://github.com/urbanairship/java-library/blob/master/src/test/java/com/urbanairship/api/push/model/notification/android/AndroidDevicePayloadTest.java
How can i do send push notification with custom key/value using AndroidDevicePayload ?
You can create your notification like this:
public PushPayload createPushPayloadCustom(String namedUser, String message) {
Notification notification = Notification.newBuilder()
.addDeviceTypeOverride(DeviceType.IOS, IOSDevicePayload.newBuilder()
.setAlert(message)
.build())
.addDeviceTypeOverride(DeviceType.ANDROID, AndroidDevicePayload.newBuilder()
.setAlert(message)
.build())
.build();
return PushPayload.newBuilder()
.setAudience(Selectors.namedUser(namedUser))
.setNotification(notification)
.setDeviceTypes(DeviceTypeData.of(DeviceType.ANDROID, DeviceType.IOS))
.build();
}
You can add to the "extras" object any key/value:
DeviceTypeData deviceTypeData = DeviceTypeData.of(DeviceType.IOS, DeviceType.ANDROID);
IOSDevicePayload iosPayload = IOSDevicePayload.newBuilder()
.setAlert(message)
.addExtraEntry("custom_ios_key", "custom value for IOS")
.build();
AndroidDevicePayload androidPayload = AndroidDevicePayload.newBuilder()
.setAlert(message)
.addExtraEntry("custom_android_key", "custom value for Android")
.build();
PushPayload payload = PushPayload.newBuilder()
.setAudience(Selectors.namedUser(email))
.setNotification(Notifications.notification(iosPayload,androidPayload))
.setDeviceTypes(deviceTypeData)
.build();
Then in the received push, you will find the object:
For more details go to urbanairship official documentation
According to the tickets at Is it possible to send binary data with STOMP over WebSockets using Spring-WebSockets? 's answer it should be possible to send and receive files using spring-websockets.
Currently I'm converting the file to an ArrayBuffer and then sending it:
fileInput.addEventListener('change', function(e) {
var file = fileInput.files[0];
var reader = new FileReader();
reader.readAsArrayBuffer(file);
stompClient.send("/app/requests." + channelId + ".files", {}, reader.result);
});
However as far as I can tell the controller doesn't receive the Bytearray in the messages payload.
#MessageMapping("requests.{channelId}.files")
public void receiveFile(#DestinationVariable String channelId, Message<?> message) throws Exception {
...
}
Could anyone please post a working example on how this should be done properly?
Thank you