QR if 语句?
我想知道是否有人解决了这个问题。我想从我的 Android 手机扫描二维码,最终将启动 Android 应用程序。如果该应用程序存在,则会启动该应用程序并提供一些独特的信息。如果该应用程序不存在,则用户将前往市场下载该应用程序。这可以做到吗?
任何帮助将不胜感激:)
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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,您可以编写一个可以做到这一点的应用程序。 条码扫描仪实际上可以完成您想要的一些操作(例如通过代码打开市场),它是开源,如果您需要一些示例,请看看那里。该项目还有一个可用于扫描 QR/条形码的库。
请记住,QR 码只不过是机器可读格式的字符串。您可以将包名称编码在代码中并进行扫描。成功执行此操作后,只需测试设备上是否存在具有该包名称的应用程序。如果是,请通过
Intent
运行它(您可以使用PackageManager.getLaunchIntentForPackage()
)。如果没有,请通过带有市场网址的Intent.ACTION_VIEW
链接到市场页面。您可以将一些额外内容编码到二维码中,具体取决于您选择的尺寸。仅从包名称中获得的好处是,已经有许多代码链接到某个应用程序的 Android 市场网站。它们的格式是
如您所见,已经包含一个包名称(此处为
com.example
)。您可以解析并使用它。如果你想要额外的东西,你必须编码你自己的二维码。
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 usePackageManager.getLaunchIntentForPackage()
for that). If not, link to the market page viaIntent.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
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.