为grome注册gcm [英] Register gcm for chrome
问题描述
我有Chrome应用使用GCM的推送通知。我有一个问题,当我不登录在铬上的帐户。我无法从GCM收到registerId。我想一个主意。当registerId为空时,我显示通知,请求用户登录到chrome并在chrome上显示登录页面帐户。但是由于安全问题,Chrome浏览器不允许从外部链接访问其设置。如何从外部链接打开chrome:// settings /?可以注册到gcm,如果我不想在Chrome上登录帐户?
我的代码:
函数setValue()
{
// var thongtin = $('#status')。val();
// var thongtin = document.getElementById('status')。innerText;
if(registrationId ==)
{
//弹出显示通知的通知。
chrome.notifications.create(getNotificationId(),{
title:'CLOUD MONITOR',
iconUrl:'gcm_128.png',
类型:'basic',
message:'您必须在google chrome上登录帐户gmail!'
},function(){});
// event click to notification
chrome.notifications.onClicked.addListener(function(){
window.location.href =chrome:// settings /
});
}
else
{
//htrap.mobile.longvan.net/device_register?regId=+ registrationId +& device = android
// document.getElementById('webviewSendData')。src =http://192.168.64.246:8080/register?REGID=+ registrationId +& DEVICE = desktop;
document.getElementById('webviewSendData')。src =http://mtraffic.longvan.net/device_register?regId=\"+registrationId+\"&device=android;
//document.getElementById('webviewSendData').src =http://192.168.64.124:8080/monitor/device_register?regId=+ registrationId +& device = android;
// var url =http://192.168.64.124:8080/monitor/device_register?regId=+ registrationId +& device = android;
// httpGet(url);
// alert(thongtin);
//document.getElementById('status').innerHTML=\"Infomation New;
//弹出通知以显示通知。
$ b
$ b
chrome.notifications.onClicked.addListener(function(){
window.location.href =chrome:// settings /
});
我将代码修改为Derek朕会功夫。
chrome.notifications.onClicked.addListener(function(){
chrome.tabs.create( {url:chrome:// settings /});
});
notify:event.onClicked的事件处理程序中的错误:TypeError:无法读取underfined的属性'create'。
解决方案恐怕目前不可能。
Chrome应用程式无法存取标签
/ windows
可以打开特权页面的API;这就是为什么Derek的建议不起作用。
将来,他们可能是使用 chrome执行此操作的一种方法。浏览器
API。请参阅此功能请求,此建议,并请留下您的使用案例的反馈。
I have a chrome Apps use push notification of GCM. I have a problem, when i don't login account on chrome. I can't receive registerId from GCM. I think a idea. When registerId empty, i show notification, request user login to chrome and show login page account on chrome. But because of security concerns , the chrome does not allow access to its setting from external links . How is open "chrome://settings/" from external links? Can register to gcm, If i don't want login account on chrome?
My code:
function setValue()
{
//var thongtin=$('#status').val();
//var thongtin = document.getElementById('status').innerText;
if(registrationId == "")
{
// Pop up a notification to show notification.
chrome.notifications.create(getNotificationId(), {
title: 'CLOUD MONITOR',
iconUrl: 'gcm_128.png',
type: 'basic',
message: 'You must sign in account gmail on google chrome!'
}, function() {});
//event click to notification
chrome.notifications.onClicked.addListener(function() {
window.location.href = "chrome://settings/"
});
}
else
{
//http://mtraffic.longvan.net/device_register?regId=" +registrationId+"&device=android
//document.getElementById('webviewSendData').src = "http://192.168.64.246:8080/register?REGID=" +registrationId+"&DEVICE=desktop";
document.getElementById('webviewSendData').src = "http://mtraffic.longvan.net/device_register?regId="+registrationId+"&device=android";
//document.getElementById('webviewSendData').src = "http://192.168.64.124:8080/monitor/device_register?regId=" +registrationId+"&device=android";
//var url = "http://192.168.64.124:8080/monitor/device_register?regId=" +registrationId+"&device=android";
//httpGet(url);
//alert(thongtin);
//document.getElementById('status').innerHTML="Infomation New";
// Pop up a notification to show notification.
}
}
This code don't run.
chrome.notifications.onClicked.addListener(function() {
window.location.href = "chrome://settings/"
});
I fix code as Derek 朕會功夫.
chrome.notifications.onClicked.addListener(function() {
chrome.tabs.create({url: "chrome://settings/"});
});
And receive error notify: Error in event handler for notifications.onClicked:TypeError: Can't read property 'create' of underfined.
解决方案 I'm afraid at the moment it's not possible.
Chrome Apps don't have access to tabs
/windows
API that can open privileged pages; that's why Derek's suggestion does not work.
In future, they may be a way to do this with chrome.browser
API. See this feature request, this proposal, and please leave feedback there with your use case.
这篇关于为grome注册gcm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!