AAP
AAP

Reputation: 253

Open Android app with browser if app is installed else open playstore

I don't have much knowledge of javascript. What I need to do is replace Firebase DeepLink

From a web page (html), open an android app if it exists, passing a parameter (This works in the app)

<a href='app://com.mycompany.myapp?jq=e44759b5-088b-41ea-9b81-faabcc0c7fe6'>Open myapp if it exists and send a parameter --> OK</a>

If the app is NOT installed, it should be redirected to google playstore and send the referrer (This works in the app)

<a id="market" href="market://details?id=com.mycompany.myapp&referrer=jq%e44759b5-088b-41ea-9b81-faabcc0c7fe6">Goto google play with referrer Ok</a>

Everything works great, if you touch the hrefs.

I implemented in $(document).ready that when navigator.userAgent is Android it executes the Android(); function.

What I need is for it to navigate directly to Google Play, just like Firebase DeepLink does. (@Google give me the solution, since you are deprecating the service in August 2025)

function Android() {

    const appURL = 'app://com.mycompany.myapp?jq=e44759b5-088b-41ea-9b81-faabcc0c7fe6';
    const playStoreURL = 'https://play.google.com/store/apps/details?id=com.mycompany.myapp&referrer=jq%e44759b5-088b-41ea-9b81-faabcc0c7fe6';

    // Intenta abrir la app
    window.location.href = appURL;

    // Si la app no está instalada, redirige directamente al Store después de un tiempo
    setTimeout(() => {
        if (!document.hidden) {
            market.click(); // Simula un clic en el enlace
        }
    }, 1500); // Espera 1500ms antes de redirigir

    // Verifica si la página se oculta (indica que la app se abrió)
    document.addEventListener('visibilitychange', () => {
        if (document.hidden) {
            console.log('La app se abrió correctamente.');
        }
    });
}

On the other hand, in browsers that do not redirect to Google Play, I tap the first href (id="market") and it navigates perfectly. I really don't understand

Upvotes: 0

Views: 28

Answers (0)

Related Questions