Javascript 如何检查chrome应用程序是否安装在其他chrome应用程序中?
我想知道我怎样才能检查一个应用程序是否安装在另一个chrome应用程序的chrome中。例如,我现在制作了app1和app2,我想知道用户在打开app2时是否安装了app1。这是通过一些ChromeAPI实现的还是不可能的 如果我不能检查用户是否安装了app1,那么他们的应用程序是某种解决方案吗 如果有必要,我可以访问chrome网站商店Javascript 如何检查chrome应用程序是否安装在其他chrome应用程序中?,javascript,google-chrome,google-chrome-app,Javascript,Google Chrome,Google Chrome App,我想知道我怎样才能检查一个应用程序是否安装在另一个chrome应用程序的chrome中。例如,我现在制作了app1和app2,我想知道用户在打开app2时是否安装了app1。这是通过一些ChromeAPI实现的还是不可能的 如果我不能检查用户是否安装了app1,那么他们的应用程序是某种解决方案吗 如果有必要,我可以访问chrome网站商店 我想做的是为那些安装我的其他应用程序的人提供一些忠诚度优惠。因为这两个应用程序都是你写的,所以使用以下程序非常简单: 在app1后台脚本中: var app2
我想做的是为那些安装我的其他应用程序的人提供一些忠诚度优惠。因为这两个应用程序都是你写的,所以使用以下程序非常简单: 在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%确定,但据我所知,一旦这个侦听器注册,情况就是这样(在后台脚本中),它将启动。OK谢谢回答被排除在外,非常感谢您的帮助。对它进行了测试;我可以确认它将唤醒一个不活动的应用程序。