I am able to send a message to a Chrome Web App using GCM. I am using a http post to: https://android.googleapis.com/gcm/send sending registrationid, applicationid, and senderid values. The message shows as a Chrome Notification on my screen. My question is - is there a command or a GCM event/function I can use to start the Chrome Web App? Google Chrome is set to run in the background.
This is my GCM Listener for message event:
chrome.gcm.onMessage.addListener(messageReceived);
It calls the messageReceived
function and in this function I get message, pop notification on the screen, and open/create the window:
chrome.notifications.create(getNotificationId(), {
title: 'GCM Message',
iconUrl: 'gcm_128.png',
type: 'basic',
message: messageString
}, function() {});
// Center window on screen.
var screenWidth = screen.availWidth;
var screenHeight = screen.availHeight;
var width = 500;
var height = 300;
chrome.app.window.create('register.html', {
id: "helloWorldID",
outerBounds: {
width: width,
height: height,
left: Math.round((screenWidth-width)/2),
top: Math.round((screenHeight-height)/2)
}
});
}