Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch App or Play Store by scanning QR code

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!
like image 762
D. Müller Avatar asked Mar 18 '16 08:03

D. Müller


People also ask

Can a QR code launch an app?

Absolutely! You have the option to link it directly to your app stores without an extra landing page. When a user scans the App Store QR Code, it will automatically detect the user's smartphone's operating system and immediately open the app in the right app store.

How do I scan a QR code to download apps from Google Play?

Step 2: Scan the QR code On your compatible Android phone or tablet, open the built-in camera app. Point the camera at the QR code. Tap the banner that appears on your Android phone or tablet. Follow the instructions on the screen to finish signing in.

Can Google Apps scan QR?

Google's image-recognition technology can scan QR codes, among other things. It's baked into Google Assistant, Google Photos, or the Google app on most Android phones, or you can also install the Google Lens app for free. Here's how to use it: Tap the color lens icon in Google Assistant, or open the Google Lens app.


3 Answers

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.

like image 139
Daniel Zolnai Avatar answered Oct 06 '22 05:10

Daniel Zolnai


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

like image 43
mattdago Avatar answered Oct 06 '22 03:10

mattdago


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);
like image 23
jonh.felix Avatar answered Oct 06 '22 04:10

jonh.felix