简体   繁体   English

Android QR检查是否已安装应用程序

[英]Android QR check if app installed

I'm scanning QR code (where specific data is coded) with QR scanner. 我正在使用QR扫描仪扫描QR码(其中编码了特定数据)。 If my app is installed on the device, the app is launched. 如果我的应用程序已安装在设备上,则会启动该应用程序。 If the app doesn't installed then it takes the user the marketplace to download the app. 如果未安装该应用程序,则需要用户将市场下载到该应用程序。 I've searched a lot on internet and only found this question. 我在互联网上搜索了很多东西,才发现这个问题。

Here's activity from manifest file which is called when QR code is scanned 这是清单文件中的活动,扫描QR码时会调用该清单文件

<activity android:name=".map.TestQrOpenActivity">
            <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="uniqueapp"/>
            </intent-filter>
</activity>

and here's the string which is coded in my QR code 这是我的QR码中编码的字符串

uniqueapp://myData

and that works perfectly if app installed in device, but if it's not installed I need to go to google play and download it basically if app exist open uniqueapp://myData else open market://details?id=com.my.package.name So is this possible? 如果在设备上安装了应用程序,则该方法非常有效,但如果未安装,则我需要转到Google Play并从根本上下载它(如果应用程序存在),请打开uniqueapp://myData否则打开market://details?id=com.my.package.name这可能吗? (I don't whant to write my own scanner) (我不想写自己的扫描仪)

Try this 尝试这个

 public static boolean intentIsAvailable(Context ctx, Intent intent) {
   final PackageManager mgr = ctx.getPackageManager();
   List<ResolveInfo> list =
      mgr.queryIntentActivities(intent, 
         PackageManager.MATCH_DEFAULT_ONLY);
   return list.size() > 0;
}

Reframing the question: 重新定义问题:

From what I'm reading, I think you want to accomplish the following: 根据我正在阅读的内容,我认为您想完成以下任务:

  1. Read my QR code with my app 使用我的应用读取我的QR码
  2. Read my QR code with any other QR reader 与其他任何QR阅读器一起阅读我的QR码
  3. Always send the QR data to my app or my website. 始终将QR数据发送到我的应用或我的网站。
  4. If my app is not installed, help the user get my app installed. 如果未安装我的应用程序,请帮助用户安装我的应用程序。

I think you solve all four of the use cases I'm describing with app links. 我认为您可以解决我通过应用程序链接描述的所有四个用例。

Android App Links: Android应用程式连结:

http://developer.android.com/training/app-links/index.html http://developer.android.com/training/app-links/index.html

With an app link you could put your URL in front, and have your app intercept it if the app is installed, and if not installed, android would simply send people to your website. 使用应用程序链接,您可以将URL放在最前面,如果安装了该应用程序,则让您的应用程序拦截它;如果未安装,则android只会将人们引到您的网站。 Once they're on your website, you could tell them they need to install your app. 他们进入您的网站后,您可以告诉他们他们需要安装您的应用程序。

Maybe this is the solution for u: 也许这是您的解决方案:

appurl appurl

Note: The app will always try the first url then fallback to the second url. 注意:应用程序将始终尝试第一个URL,然后回退到第二个URL。 For example under "iOS - iPhone" if you wanted to open the tweetbot app you would add tweetbot:// to the first text field then add the iTunes store url to the second text field. 例如,在“ iOS-iPhone”下,如果要打开tweetbot应用程序,则将tweetbot://添加到第一个文本字段,然后将iTunes store网址添加到第二个文本字段。 When a user taps on the link if they are on their iPhone it will check to see if the user has tweetbot installed, if not it will take them to the iTunes store. 当用户点击链接(如果他们在iPhone上)时,它将检查用户是否安装了tweetbot,否则,将把他们带到iTunes商店。

It generates a URL and a QR Code Hope this is what u need. 它会生成一个URL和一个QR码希望这是您需要的。

I recommend using ZXing Android Embedded . 我建议使用ZXing Android Embedded

This way you don't have to write your own scanner and the user doesn't have to install anything else. 这样,您不必编写自己的扫描仪,用户也无需安装其他任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM