Android的,如何读取QR code。在我的应用程序? [英] Android, How to read QR code in my application?
问题描述
在我的应用程序需要读取的QR code。我搜索网,发现诚codeS然而很多开发商不得不问题,使用它,它似乎是越野车!
如果我认为我的客户已经安装在他们的设备上的QR读者,我如何使用这些应用程序,并通过隐含的意图给他们打电话?
如果用户没有任何QR读者,会发生什么样的应用?如果它崩溃,请问用户下载例如QrDroid,之后使用它?
尝试{
意向意图=新的意图(com.google.zxing.client.android.SCAN);
intent.putExtra(SCAN_MODE,QR_ code_MODE); //PRODUCT_MODE的吧codeS
startActivityForResult(意向,0);
}赶上(例外五){
乌里marketUri = Uri.parse(?市场://细节ID = com.google.zxing.client.android);
意图marketIntent =新的意图(Intent.ACTION_VIEW,marketUri);
startActivity(marketIntent);
}
和 onActivityResult():
@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
super.onActivityResult(要求code,因此code,数据);
如果(要求code == 0){
如果(结果code == RESULT_OK){
字符串内容= data.getStringExtra(SCAN_RESULT);
}
如果(结果code == RESULT_CANCELED){
//处理取消
}
}
}
In my application I need to read Qr code. I searched the net and found Zing codes however lots of developers had problem with using it and it seems it is buggy!
If i assume that my customers has qr reader installed on their device, how can i use those applications and call them via implicit intents?
if user doesn't have any qr reader, what will happen to the application? if it crashes, may i ask user to download for example QrDroid and after that use it?
try {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes
startActivityForResult(intent, 0);
} catch (Exception e) {
Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
startActivity(marketIntent);
}
and in onActivityResult():
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = data.getStringExtra("SCAN_RESULT");
}
if(resultCode == RESULT_CANCELED){
//handle cancel
}
}
}
这篇关于Android的,如何读取QR code。在我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!