QR if statement?

て烟熏妆下的殇ゞ 提交于 2019-12-12 18:07:43

问题


I was wondering if anyone has solved this problem. I want to scan a QR code from my android phone that will ultimately launch an Android App. If the app exists, the app is launched with some unique information. If the app doesn't exist then it takes the user the marketplace to download the app. Can this be done?

Any help will greatly be appreciated :)


回答1:


Sure, you can write an app that can do that. Barcode Scanner actually does some of the things you want (e.g. opening the market from a code), it's open source, if you need some samples take a look there. The project also has a library that you can use to scan QR-/barcodes.

Keep in mind that a QR-code is nothing else than a String in a machine-readable format. You can encode a package name in a code and scan that. When you successfully did that, just test if the app with that package name is present on the device. If yes, run it via an Intent (you can use PackageManager.getLaunchIntentForPackage() for that). If not, link to the market page via Intent.ACTION_VIEW with a market url. You may encode some extras into the QR-codes, depending on which size you choose for these.

The benefit from the package name only is that there are many codes already out there that link to the android market site of a certain app. Their format is

market://search?q=pname:com.example

As you can see, theres already a packagename included (here com.example). You can parse and use it. If you want extras, you have to encode your own qr-codes though.



来源:https://stackoverflow.com/questions/7263198/qr-if-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!