The getInstalledRelatedApps()
method returns a promise that resolves with an array of objects representing any related platform-specific apps or Progressive Web Apps that the user has installed. This could be used for content personalization such as removing "install our app" banners from the web app if the platform-specific app and/or PWA is already installed.
getInstalledRelatedApps()
can be used to check for the installation of Universal Windows Platform (UWP) apps, Android apps, and PWAs that are related to the web app calling this method.
To associate the invoking web app with a platform-specific app or PWA, two things must be done:
- The invoking web app must be specified in the
related_applications
member of its manifest file. - The platform-specific app or PWA must have its relationship with the invoking app defined.
Defining the relationship is done in a different way depending on the type of app:
- An Android app does this via the Digital Asset Links system.
- A Windows UWP app does this via URI Handlers.
- A PWA does this via:
- A self-defining entry inside its own
related_applications
manifest member in the case of a PWA checking if it is installed on the underlying platform. - An
assetlinks.json
file in its /.well-known/
directory in the case of an app outside the scope of the PWA checking whether it is installed.
See Is your app installed? getInstalledRelatedApps() will tell you! for more details on how to handle each one of these cases.
getInstalledRelatedApps()
A Promise
that fulfills with an array of objects representing any installed related apps. Each object can contain the following properties:
-
id
Optional
-
A string representing the ID used to represent the application on the specified platform. The exact form of the string will vary by platform.
platform
-
A string representing the platform (ecosystem or operating system) the related app is associated with. This can be:
-
url
Optional
-
A string representing the URL associated with the app. This is usually where you can read information about it and install it.
-
version
Optional
-
A string representing the related app's version.
The related app information must have been previously specified in the related_applications
member of the invoking web app's manifest file.
const relatedApps = await navigator.getInstalledRelatedApps();
console.table(relatedApps);
const psApp = relatedApps.find((app) => app.id === "com.example.myapp");
if (psApp && doesVersionSendPushMessages(psApp.version)) {
return;
}
Note: In this example, doesVersionSendPushMessages()
is a theoretical developer-defined function; it is not provided by the browser.