Launch App or Play Store by scanning QR code

Viewed 25357

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!
5 Answers

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

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);

        }

    }

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).

Related