Launch App or Play Store by scanning QR code
Asked Answered
C

5

12

I have an Android app with package name like my.test.app. I want to generate a QR code, which:

  • If my app is installed: Open the app
  • If not installed yet: Open the app page in PlayStore

Is there a possible way to do this, so that any Android QR scanner can handle the actions described above? I couldn't find an question/answer which realizes both... Thank you!

EDIT - What I did so far I added the following to my "App to open" manifest:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:exported="true" >
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="my.test.app"/>
        </intent-filter>
    </activity>
  ...
</application>

When I generate a QR code with content my.test.app://test and scan it, the QR reader app shows the correct content, but won't open my app!

2nd EDIT - Tried some URLs

I just tried to set a few other URLs in my Manifest's intent-filter:

  1. <data android:scheme="http" android:host="play.google.com" android:pathPrefix="/store/apps/details?id=my.test.app"/>
    • this asks me whether to open the URL in browser or in PlayStore, if I scan the QR code with content http://play.google.com/store/apps/details?id=my.test.app
    • BUT WON'T OPEN MY APP IF INSTALLED!


2. <data android:scheme="http" android:host="myapp.com" android:pathPrefix="/barcode"/>

  • this opens my app when scanning the QR code http://myapp.com/barcode! BUT the problem would be, that there's no solution/target address when the app is not installed when scanning! A redirect via HTML site would be possible maybe, but I don't want to use a HTML server for this!
Camellia answered 18/3, 2016 at 8:30 Comment(6)
I know you can at least get the a URI to the Play store. I'm not sure about starting your app if it is installedNikethamide
Possible duplicate of Android start application from QR Code with paramsNikethamide
You may need to add an Intent filter to the Manifest for a custom URI as suggested here. https://mcmap.net/q/1011863/-qr-code-for-launching-a-native-applicationNikethamide
For me, e.g. I have installed the App "QR Code Reader" (play.google.com/store/apps/details?id=me.scan.android.client). When I create a QR code with content "my.test.app://test" it shows the content on scanning, but won't open my app...Gandhi
The action depends on the application you use to read the QR code.Hamster
I just tried 2 other QR reader apps, one of them worked for my own schema, but the others didn't. Is there no "app-independent" solution?Gandhi
R
2

You could create a URL which would be recognized by your app, and would open it automatically (you can declare these in your manifest). You could make that page display something like "Redirecting you to Google Play...", and then redirect in a few seconds.

So if they have the app installed, the URL would trigger opening it, if it is not opened, it would stay in the browser and redirect to Google Play.

Repro answered 18/3, 2016 at 8:38 Comment(4)
Yes this would be a possible solution. The problem seems to be, that the QR reader apps have different behaviours when scanning tags with own schema.Gandhi
You don't need an own schema. Just use an address like http://myapp.com/barcodeRepro
Ok, I tried some other urls, see my 2nd edit above in the question.Gandhi
I'm not sure if the app id is part of the path prefix, since it more of a parameterRepro
C
2

This is the solution I've found for the same issue: 1. I've created a simple http landing-page with 2 badges, the 1st for Google-play android app and the 2nd for the Apple App Store app. (https://www.example.com/landingPage) 2. I've added the following lines in the manifest (as well described above):

    <data
                android:scheme="https"
                android:host="www.example.com"
                android:pathPrefix="/landingPage" />
</intent-filter>
  1. I've generated a QrCode from the URL https://www.example.com/landingPage. You can eventually add some parameters at the end to handle in the App in the future (https://www.example.com/landingPage&param1=value1 ecc.).

So, when you catch the QrCode for the first time, you are directed through the browser to the landing page and can choose the app to download and install. The coming times you catch the QrCode the device show you the app list to use to execute it and you will find there the app just installed. This works fine for me

Containment answered 29/2, 2020 at 15:15 Comment(0)
D
1
you can through a html page

    please note Android_URL like [scheme]://[host]/[path]?[query]

    scheme:which App  you  want to start
    host:note
    path:key 
    query:Key and  value 

    Android_URL = "myapp://www.test.com/openwith?uid=123";

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta content="telephone=no" name="format-detection" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
        <title>open or download  App</title>

    <script src="assets/plugins/jquery-1.8.3.min.js" type="text/javascript"></script>
    </head>
    <body>

    <a id="vlink" onClick="try_to_open_app()" style="display:none"></a>
    <script>
    var browser={    
            versions:function(){            
                var u = navigator.userAgent, app = navigator.appVersion;      
            };
        }()
    } 
        var Android_URL = "myapp://www.test.com/openwith?uid=123";

        function open_link() {
            window.location=mtUrl;
        }
        function try_to_open_app() {
            setTimeout('open_link()', 500);
        }
        //Android
        else if(browser.versions.android){     
            document.getElementById("vlink").setAttribute("href",Android_URL);
            document.getElementById("vlink").click();
        }

        else{
            open_link();
        }
    </script>
    </body>
    </html>


**android** 
<activity
    android:name="net.laobanquan.im.splash.StartActivity"
    android:launchMode="singleTop"
    android:screenOrientation="portrait"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<!-- new in -->
<activity
    android:name="net.test.WebStartActivity"
    android:screenOrientation="portrait">

    <intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>

        <data android:scheme="myapp" android:host="www.test.com" android:path="/openwith"/>
    </intent-filter>

</activity>

**activity**

    String action = getIntent().getAction();
    String uid = null;
    if(Intent.ACTION_VIEW.equals(action)){  
        Uri uri = getIntent().getData();  
        if(uri != null){  
            uid = uri.getQueryParameter("uid");
        }  
    }
    Log.d(TAG, uid);
Demoralize answered 18/3, 2016 at 8:52 Comment(1)
This would open the app if it is already installed on my device, but wouldn't work if not installed yet, wouldn't it? I also don't want to use a web-server for this. I need a "native android and qr code solution"Gandhi
I
1

Your Will not find a QR Scanner App that will trigger an Intent to open your App.

Most QR Code Scanners including mine Implement the basic Intents(Call,http urls,contact etc..)

it is Upon the QR App Developers to handle the intent of opening your app or not.

FYI All content of the QR Code scan results are returned as a string, so Most Qr Scanning Apps don't handle all intents in the Android Core they look at the structure of the string and trigger the basic intents they can afford.

If the scan result has a string that starts with "http" then we trigger a browser intent, etc..

You should just generate a QR code of your package name and hope QR Code Scanner Dev's implemented a global Intent that recognizes packages.

if Assuming they implement a Global Intent to open an Apps via detecting packages, You should Generate a QR Code of your App's package name eg my.test.app

Here is how that Intent is Implemented from Scanner's side

// It checks for the app if it exists on the phone, lunch it otherwise, it will search for the app in google play app in the phone and to avoid any crash, if no google play app installed in the phone, it will search for the app in the google play store using the browser :

public void LunchAnotherApp(String PackageNameFromScan) {

        final String appPackageName = PackageNameFromScan;

        Intent intent = getPackageManager().getLaunchIntentForPackage(appPackageName);
        if (intent != null) {

            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

        } else {

            onGoToAnotherInAppStore(intent, appPackageName);

        }

    }

    public void GoToAnotherInAppStore(Intent intent, String appPackageName) {

        try {

            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("market://details?id=" + appPackageName));
            startActivity(intent);

        } catch (android.content.ActivityNotFoundException anfe) {

            intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName));
            startActivity(intent);

        }

    }
Ilka answered 29/2, 2020 at 15:51 Comment(0)
M
0

The question seems to be asking to open an app when QR is scanned, and if app isn't installed, open a web page. Normally, users would open some app in phone to scan QR Code.

Apple has developed a feature called deep linking, which opens registered apps when a QR Image is scanned by phone camera, if you have Apple iOS 11. Otherwise, it'll open up a web browser to either a website or redirect to app store to download app (based on fallback setting included in QR).

For users with earlier operating systems, "open your QR code scanning app to scan." (as usual). For those who don't have a QR scanning app, they'd need to download one (to scan QR Codes), or upgrade to a device that supports a similar function to Deep Linking.

Either approach seems to have the same goal (to open an app, either by scanning QR with data or opened by user to scan data in QR).

Malenamalet answered 20/11, 2020 at 5:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.