Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法打开扩展gcm通知_Javascript_Google Chrome App - Fatal编程技术网

Javascript 无法打开扩展gcm通知

Javascript 无法打开扩展gcm通知,javascript,google-chrome-app,Javascript,Google Chrome App,我正在为chrome编写扩展gcm通知。当我在chrome上登录gmail帐户时,首先,我可以正常打开扩展。我关闭扩展应用程序,重新打开扩展应用程序,但应用程序无法显示。当我在chrome上注销gmail帐户时,我可以关闭打开的正常应用程序。我不知道为什么 Background.js // Returns a new notification ID used in the notification. var registerWindowCreated = false; function getN

我正在为chrome编写扩展gcm通知。当我在chrome上登录gmail帐户时,首先,我可以正常打开扩展。我关闭扩展应用程序,重新打开扩展应用程序,但应用程序无法显示。当我在chrome上注销gmail帐户时,我可以关闭打开的正常应用程序。我不知道为什么

Background.js

// Returns a new notification ID used in the notification.
var registerWindowCreated = false;
function getNotificationId() {
var id = Math.floor(Math.random() * 9007199254740992) + 1;
 return id.toString();
}

 function messageReceived(message) {
 // A message is an object with a data property that
  // consists of key-value pairs.

 // Concatenate all key-value pairs to form a display string.
 var messageString = "";
 for (var key in message.data) {
  if (messageString != "")
  messageString += ", "
  messageString += message.data[key];
//messageString += key + ":" + message.data[key];
 }
 console.log("Message received: " + messageString);

 // Pop up a notification to show the GCM message.
 chrome.notifications.create(getNotificationId(), {
title: 'NETWORK MONITOR',
iconUrl: 'gcm_128.png',
type: 'basic',
message: messageString
 }, function() {
if(registerWindowCreated==false)
{
chrome.app.window.create(
  "index.html",
  {  width: 800,
     height: 600,
     frame: 'chrome'
  },
  function(appWin) {}
);
}
});
}

function firstTimeRegistration() {
chrome.storage.local.get("registered", function(result) {
// If already registered, bail out.
if (result["registered"])
  return;

registerWindowCreated = true;
chrome.app.window.create(
  "index.html",
  {  width: 800,
     height: 600,
     frame: 'chrome'
  },
  function(appWin) {}
);
});
}

// Set up a listener for GCM message event.
chrome.gcm.onMessage.addListener(messageReceived);

// Set up listeners to trigger the first time registration.
chrome.app.runtime.onLaunched.addListener(firstTimeRegistration);
chrome.runtime.onInstalled.addListener(firstTimeRegistration);
chrome.runtime.onStartup.addListener(firstTimeRegistration);
manifest.json

{
"name": "Network Monitor",
"description": "Chrome platform app.",
"manifest_version": 2,
"version": "1.0",
"app": {
"background": {
  "scripts": ["background.js"]
 }
},
"permissions": ["gcm", "storage", "notifications","http://*.longvan.net/","webview"],
"icons": { "128": "gcm_128.png" }
}

对不起,但很难理解你在问什么。似乎是语言问题。你能试着重新格式化吗?我构建应用程序扩展。首先,我打开应用程序,它显示正常。然后,我关闭应用程序。我重新打开应用程序,它不显示gui。我连续点击打开它,但没有看到任何东西显示。如果设置了registered,它似乎不应该显示GUI。您没有在index.html中显示发生了什么。谢谢!我成功了。chrome.app.window.create处出错。