Android Push notification- Only show the notification message to user - javascript

I am trying to include Push Notification in my Hybrid Application.
While doing this, I am able to send the push notification message from rest client and also able to receive the notification in my Android device.
Now I want to the device user to get only the alert message which I send from the server.
For example:
In the body of my Post method,I am sending:
{
"alert": "Hello android"
}
Then, only "Hello Android" should be visible to him, even if I open the application.
Currently,when I test the above example,
when the user's app is open, he gets an alert message with details related to gcm sender, collapse_key information, apart from the alert message.
I am attaching screenshot here
function processNotification(notification) {
console.log("Hi! You have received a notification: " + JSON.stringify(notification));
alert("Hi! You have received a notification: " + JSON.parse(notification));
if(sap.Push.isPlatformIOS()){
sap.Push.resetBadge(resetBadgeSuccess);
}
}
Any Help would be appreciated

Related

Different behavior between development and production

I developed a Web Add-In for Outlook for my Company, which will set an E-Mail Header on an outgoing Mail to indicate whether a mail shall be encrypted by the MTA or not. Additionally, there shall be an indicator on the saved outgoing mail, to make it easy for the user to determine if the Mail was encrypted or not.
To archive this, I hook into the OnMessageSend event and simple change the icon and text of a notification.
It works like expected as long I run the Add-In locally in development. But as soon the Add-In is on the Production Server, it does not change the last notification within the OnMessageSend event. The saved mail, from the outgoing folder, still shows the "This Message will be encrypted" notification and not the indicator.
To fix this I tried several tricks like to implement a wait for the event to complete but nothing worked out. The Add-In does not change the indicator notification when put on the production server, just like it does locally in development.
Do maybe someone knows what's the problem here?
This is the Code snipped which will change the Notification on a Mail, when the User click the "Send" Button, based on the Security Settings for this mail:
// Define a callback function for checking the header.
function eventCallback(asyncResult) {
// Get the event pointer from asyncContext.
let event = asyncResult.asyncContext;
// If the function was executed successful.
if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
// If we got a value back aka there is our header,...
if (asyncResult.value) {
// ..if this is a dismiss routine set the message again.
if (dismiss) {
Office.context.mailbox.item.notificationMessages.replaceAsync("information", {
type: "informationalMessage",
message: "Ihre Nachricht wird Verschlüsselt.",
icon: "Icon.Lock.16x16",
persistent: true
});
} else {
// ..and set a new notification with a own icon to reflect the encryption state on the outgoing mail.
Office.context.mailbox.item.notificationMessages.replaceAsync("information", {
type: "informationalMessage",
message: "Diese Nachricht wurde Verschlüsselt.",
icon: "Icon.Cryptmail.16x16",
persistent: true
});
}
} else if (dismiss) {
Office.context.mailbox.item.notificationMessages.replaceAsync("information", {
type: "informationalMessage",
message: "Verschlüsselung wurde entfernt.",
icon: "Icon.Unlock.16x16",
persistent: true
});
}
} else {
let message = "Ein Fehler ist aufgetrehten: " + JSON.stringify(asyncResult.error);
event.completed({ allowEvent: false, errorMessage: message });
}
// Reset the dismiss global variable.
dismiss = false;
// Close the event, we are done here.
event.completed({ allowEvent: true });
}
The Notification when a user click the encrypt button on a mail:
The Message will be encrypted
The Notification of the saved outgoing mail in development:
This Message was encrypted
The Notification of the saved outgoing mail in production:
The Message will be encrypted

Consuming a message sent by OneSignal

I have vue js application and i am consuming messages sent from a php script like this
document.addEventListener("deviceready", OneSignalInit, false);
function OneSignalInit() {
// Uncomment to set OneSignal device logging to VERBOSE
// window.plugins.OneSignal.setLogLevel(6, 0);
// NOTE: Update the setAppId value below with your OneSignal AppId.
window["plugins"].OneSignal.setAppId("");
window["plugins"].OneSignal.setNotificationOpenedHandler(function(jsonData) {
console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
});
// iOS - Prompts the user for notification permissions.
// * Since this shows a generic native prompt, we recommend instead using an In-App Message to prompt for notification permission (See step 6) to better communicate to your users what notifications they will get.
window["plugins"].OneSignal.setNotificationReceivedHandler(function(jsonData) {
this.$router.push({path: '/my_ads'});
});
window["plugins"].OneSignal.promptForPushNotificationsWithUserResponse(function(accepted) {
console.log("User accepted notifications: " + accepted);
});
}
In my code above, this gives me a notification that shows on android. I would like to send a message that do not require a notification prompt but i would like to consume the message sent inside my application i.e use the message sent and do something with it i.e go to another route
this.$router.push({path: '/another_route'});
How can i do that?

unable to broadcast a user disconnection in socket.io

i am new to socket.io & nodejs. i have been writing a tictactoe game and i have a problem in it, my purpose is if someone refresh the page or close the browser let his/her opponent know . i know i should do this with disconnect event and here is what i try, but it is not working .
server side
socket.on('disconnect', function() {
socket.emit('user:disconnect');
});
client side
socket.on('user:disconnect', function() {
var message = player.getPlayerName() + ' leaves';
socket.emit('gameEnded', {room: this.getRoomId(), message: message,id:player.getPlayerId(),gameid: this.getGameId(),winType:"leave"});
});
also, i need to know how to get the room of disconnected user .
i already saw this but i just want to send the users in a room not all users in the whole application.
server.js
socket.on('disconnect', function() {
socket.emit('user:disconnect');
});
In the above code if a user named 'xxx' is disconnected, server is emitting 'user:disconnect' to the same user. You have to find the socket connection of other player and emit the event to that client.
You can achieve your goal by joining both the clients in a room and send message to other user in the room.
socket.join('room1');
io.sockets.in('room1').emit('user:disconnect');
Otherwise you have to store all clients as mentioned below and send message to the specific client using the following code.
var users = {
'client1': [socket object],
'client2': [socket object],
'client3': [socket object]
}
users['client3'].emit('user:disconnect')

Chromecast not receiving messages over CastMessageBus

I'm trying to initialise the cast message bus on my
receiver application. I am using the
CastReferencePlayer Sample I'm able to initialise the channel at launch, and
receive one message.
But after media is playing, I'm not able to receive
any additional messages over the channel using the same send methods on
the sender. My sender is an iOS Device
Where is the best place to init the message bus to ensure that the channel
is open to receive messages throughout the life of the app?
I am currently starting the channel
in sampleplayer.CastPlayer.prototype.start = function(). But I'm not sure if this is the correct place to start the message bus as I'm only receiving the message once at startup (i.e. before the media starts to play).
sampleplayer.CastPlayer.prototype.start = function() {
var messageBus = this.receiverManager_.getCastMessageBus(
"urn:x-cast:com.myTestChannel.app",
cast.receiver.CastMessageBus.MessageType.JSON);
messageBus.onMessage = function(event) {
var message = event.data;
if (message.testID) {
console.log("Message received");
} else if (message.someKey) {
console.log("pause message received");
}
};
this.receiverManager_.start();
};
I have tried to place the channel creation code in a window.onload function inside my player.js but this reacts the same as before (i.e. initial message only).
Does anyone have any idea where I should be placing the code to init the channel?
Any help would be appreciated.
EDIT: I have done some more investigating and discovered that it is just my iOS sender that will not send multiple messages to the receiver. I have tried both android and chrome and multiple messages work.
Is anyone aware of problems with sending messages from an iOS sender.
The problem with my code was in my sender.
The sendTextMessage method was not firing the after the first instance due to the my reference to the cast channel being destroyed.

Facebook apprequest notification received but not showing message

The notification is received but without the message.
Any idea why? Did facebook removed messages even that it's in the dev doc?
function newInvite(){
FB.ui({
method: 'apprequests',
title: 'Invite friends to play',
message: 'Come to play.',
new_style_message: true, // added this after a search but doesnt work either
filters: ['app_non_users']
});
}
https://developers.facebook.com/docs/games/services/gamerequests#dialogparameters:
message: A plain-text message to be sent as part of the request. This text will surface in the App Center view of the request, but not on the notification jewel
So yes, if you are talking about the notification jewel (the little globe symbol in the top bar in the web UI), this is supposed to work this way - there it will only show a text given by Facebook, “Foobar send you a request on Appname” or something like that.
Only the detailed App Center view under https://www.facebook.com/games/activity is supposed to show the message the user sending the request typed in.

Categories