如何检查Chrome应用是否安装在其他Chrome应用中?

dra*_*ord 4 javascript google-chrome google-chrome-app

我想知道如何从不同的Chrome应用程序检查应用程序是否安装在Chrome中.例如,我现在已经创建了app1和app2我想知道用户是否在他/她打开app2时安装了app1.这可能是由一些chrome api或这是不可能的吗?

如果我无法检查用户是否安装了app1那么他们的某种解决方案是什么?

如果重要的话,我可以访问chrome webstore.

我想要做的是为那些安装我的其他应用程序的人提供一些忠诚度特权.

Xan*_*Xan 6

由于您编写了这两个应用程序,因此使用外部消息传递非常简单:

在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);
  }
);
Run Code Online (Sandbox Code Playgroud)

app2中的某个地方:

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