Skip to main content

How to Check if a Native App is Installed

Let’s look at the Google Maps example in this case. It is required to include a JavaScript function that checks whether the Google Maps app is installed on the user's device. This JS function must be compatible with both Android and iOS platforms. The function will utilize platform-specific APIs to verify the presence of the Google Maps application, ensuring a consistent user experience across different operating systems. Below is the required function implementation:

const handleGoDirection = () => {
window?.flutter_inappwebview
?.callHandler('getAppInstalled', {
android: 'com.google.android.apps.maps',
ios: 'comgooglemaps://',
})
?.then(function (e) {
window.addEventListener(
'getAppInstalledResultEvent',
(eventDetail) => {
if (String(eventDetail.detail).toLowerCase() == 'true') {
// open redirect google maps action sheet
setIsOpenGoogleMapsRedirectInfoMessageActionSheet(true);
} else {
// open redirect app store action sheet
setIsOpenGoogleMapsRedirectAppStoreInfoMessageActionSheet(true);
}
setIsOpenDetailActionSheet(false);
},
{
once: true,
}
);
});
};

This function ensures that the MiniApp can determine the availability of the Google Maps app on the user's device, enabling the app to provide appropriate feedback or alternatives based on the check result.