TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Basit Khan
NA
336
121.4k
Google Chrome Push Notification
Dec 21 2017 1:51 AM
I successfully send the notification to google chrome. My service-worker.js is below.
'use strict'
;
self.addEventListener(
'push'
,
function
(event) {
console.log(
'Received a push message'
, event);
var
title =
'Pushup Notification'
;
var
body =
'Test'
;
var
icon =
'images/icon.png'
;
var
badge =
'images/badge.png'
var
tag =
'simple-push-demo-notification-tag'
;
event.waitUntil(
self.registration.showNotification(title, {
body: body,
icon: icon,
badge: badge,
tag: tag
})
);
});
self.addEventListener(
'notificationclick'
,
function
(event) {
console.log(
'On notification click: '
, event.notification.tag);
// Android doesn’t close the notification when you click on it
// See: http://crbug.com/463146
event.notification.close();
// This looks to see if the current is already open and
// focuses if it is
event.waitUntil(clients.matchAll({
type:
'window'
}).then(
function
(clientList) {
for
(
var
i = 0; i < clientList.length; i++) {
var
client = clientList[i];
if
(client.url ===
'/'
&&
'focus'
in
client) {
return
client.focus();
}
}
if
(clients.openWindow) {
return
clients.openWindow(
'/'
);
}
}));
});
Below is the sending code to Google Chrome.
Public
Function
SendNotification(
ByVal
deviceId
As
String
,
ByVal
message
As
String
)
As
String
Dim
SERVER_API_KEY
As
String
=
"API KEY"
Dim
SENDER_ID =
"Sender ID"
Dim
value = message
Dim
tRequest
As
WebRequest
tRequest = WebRequest.Create(
"https://android.googleapis.com/gcm/send"
)
tRequest.Method =
"post"
tRequest.ContentType =
" application/x-www-form-urlencoded;charset=UTF-8"
tRequest.Headers.Add(
String
.Format(
"Authorization: key={0}"
, SERVER_API_KEY))
tRequest.Headers.Add(
String
.Format(
"Sender: id={0}"
, SENDER_ID))
Dim
postData
As
String
= (Convert.ToString((Convert.ToString(
"collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message="
) & value) +
"&data.time="
+ System.DateTime.Now.ToString() +
"®istration_id="
) & deviceId) +
""
Console.WriteLine(postData)
Dim
byteArray
As
[
Byte
]() = Encoding.UTF8.GetBytes(postData)
tRequest.ContentLength = byteArray.Length
Dim
dataStream
As
Stream = tRequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim
tResponse
As
WebResponse = tRequest.GetResponse()
dataStream = tResponse.GetResponseStream()
Dim
tReader
As
New
StreamReader(dataStream)
Dim
sResponseFromServer
As
[
String
] = tReader.ReadToEnd()
tReader.Close()
dataStream.Close()
tResponse.Close()
Return
sResponseFromServer
MsgBox(
"ok"
)
End
Function
What my question is When i'm sending with above code the push up notification showing whatever in the Hard coded title and body which is in service-worker.js. How to show my message which is in above .net code.
Thanks, Basit.
Reply
Answers (
0
)
Compilation error, metadata file '.dll' could not be found
change back color if gridView cells has empty.