Reputation: 3426
I have an Android app with package name like my.test.app
. I want to generate a QR code, which:
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:
<data android:scheme="http" android:host="play.google.com" android:pathPrefix="/store/apps/details?id=my.test.app"/>
http://play.google.com/store/apps/details?id=my.test.app
2. <data android:scheme="http" android:host="myapp.com" android:pathPrefix="/barcode"/>
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!Upvotes: 12
Views: 35074
Reputation: 3681
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).
Upvotes: 0
Reputation: 847
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);
}
}
Upvotes: 1
Reputation: 21
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>
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
Upvotes: 2
Reputation: 11
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);
Upvotes: 1
Reputation: 16920
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.
Upvotes: 2