如何使用Zxing在安卓 [英] How to use Zxing in android
问题描述
我是新来Zxing。我做用zxing在我的Android应用程序吧code转换。任何人都可以指导我如何包括zxing到Android设备。
I am new to Zxing. I am doing barcode conversion using zxing in my android application. Can anyone guide me how to include zxing to android device.
推荐答案
如果该zxing吧code扫描仪安装在移动,它很容易的:
If the zxing barcode scanner is installed in the mobile, its very easy:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
startActivityForResult(intent, 0);
和 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"); //this is the result
} else
if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
如果它没有安装:美国可以把这个code。在try-catch块,并捕捉异常,ü可以做到这一点:
If its not installed: u can put this code in try-catch block and catching the exception, u can do this:
Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
startActivity(marketIntent);
因此重定向应用程序,以安卓市场
和乌尔应用程序继续运行一次,如果吧code扫描
安装。
So it redirects the app to android market
and ur app continues running once if the barcode scanner
is installed.
如果妳不想使用在乌拉圭回合应用程序中的其他应用程序,U必须下载zxing库,并尝试使用的类core.jar添加文件(它采用Apache Ant创建)。按照本教程做到这一点: https://github.com/zxing/zxing/wiki/Getting-Started-Developing
If u dont want to use the other app in ur app, U have to download zxing library and try using the classes from core.jar file(it is created using apache ant). Follow this tutorial to do that: https://github.com/zxing/zxing/wiki/Getting-Started-Developing
所有意图选项都可以在这里找到:
All Intent options can be found here:
<一个href="http://$c$c.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/Intents.java" rel="nofollow">http://$c$c.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/Intents.java
这篇关于如何使用Zxing在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!