我可以使用 GCM 向 Chrome Web App 发送消息。我正在使用 http 发布到: https : //android.googleapis.com/gcm/send 发送registrationid、applicationid 和senderid 值。该消息在我的屏幕上显示为 Chrome 通知。我的问题是 - 我可以使用命令或 GCM 事件/函数来启动 Chrome Web 应用程序吗?谷歌浏览器设置为在后台运行。
这是我的消息事件的 GCM 侦听器:
chrome.gcm.onMessage.addListener(messageReceived);
它调用该messageReceived
函数,在此函数中我收到消息,在屏幕上弹出通知,并打开/创建窗口:
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)
}
});
}