I have a PWA application where I check whether the application is in standalone mode(code snippet below) else prompt user with the Install Banner.
let windowNav: any = window.navigator;
if (window.matchMedia('(display-mode:standalone)').matches || windowNav.standalone) {
this.isStandAlone = true;
}
Recently, I have also created a TWA app for the same. Now when I install the APP from the playstore the below check fails though the app is in standalone mode. Is there a different way to check the standalone mode in TWA applications?Or a way to check that the APP is a TWA app?
Thanks
Standalone is not so useful in case of TWA. if u want to know that your application is running on TWA, What you can do is set a sessionStorage as a flag, If certain conditions met. When ever a TWA app is open u can get the package name like com.example inside document.reffer property and also you can pass some value in query Param to check ur app. Is opened. So, this will look like this.
If(document.referrer == 'android-app://com.example' && location.href.includes('?twa=true')){ sessionStorage.isTwa = 1; }
When app opens, a session starts, and isTwa will be set as 1, when app is closed that session ends as well. Same as a chrome tab session.