【问题标题】:How to check if a chrome app is installed in a different chrome app?如何检查 chrome 应用程序是否安装在不同的 chrome 应用程序中?
【发布时间】:2014-11-03 15:24:59
【问题描述】:

我想知道如何检查一个应用程序是否从不同的 chrome 应用程序安装在 chrome 中。例如,我现在制作了 app1 和 app2,我想知道用户在打开 app2 时是否安装了 app1。这可以通过某些 chrome api 实现还是不可能?

如果我无法检查用户是否安装了 app1,那么他们是否可以解决某种问题?

如果这很重要,我确实可以访问 chrome 网上商店。

我想做的是为安装我其他应用的用户提供一些忠诚度福利。

【问题讨论】:

  • 你为什么要这个?我们无法在不知道您想要实现什么的情况下提供解决方法。
  • 这样我就可以为安装了我的其他应用程序的人提供某种忠诚度福利。

标签: javascript google-chrome google-chrome-app


【解决方案1】:

由于您编写了这两个应用程序,因此使用External Messaging 非常简单:

在app1后台脚本中:

var app2id = "abcdefghijklmnoabcdefhijklmnoab2";
chrome.runtime.onMessageExternal.addListener(
  // This should fire even if the app is not running, as long as it is
  //   included in the event page (background script)
  function(request, sender, sendResponse) {
    if(sender.id == app2id && request.areYouThere) sendResponse(true);
  }
);

app2 中的某处:

var app1id = "abcdefghijklmnoabcdefhijklmnoab1";
chrome.runtime.sendMessage(app1id, {areYouThere: true},
  function(response) {
    if(response) {
      // Installed and responded
    } else {
      // Could not connect; not installed
    }
  }
);

【讨论】:

  • 我喜欢这个答案,但是两个应用程序必须同时运行才能正常工作吗?
  • 嗯。我不是 100% 确定,但据我所知,一旦注册了这个监听器(在后台脚本中),它就会触发。
  • 好的,谢谢答案已被排除,感谢您的帮助,非常感谢。
  • 测试过;我可以确认它会唤醒一个不活动的应用程序。
猜你喜欢
  • 1970-01-01
  • 2011-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多