使用Zxing的Android条形码扫描仪
我想在android项目中集成Zxing(我是初学者) 我已经看到这里描述的方法是不被鼓励的,最好的方法是通过本文中所说的意图 p、 s:我不想在我的设备上安装条形码扫描仪 我已在我的项目中加入了所需的课程: 我的测试代码: 我真的不明白怎么用这种方式来做:(我真的不明白,这就是我想用的) 你知道怎么做吗使用Zxing的Android条形码扫描仪,android,android-intent,barcode,zxing,barcode-scanner,Android,Android Intent,Barcode,Zxing,Barcode Scanner,我想在android项目中集成Zxing(我是初学者) 我已经看到这里描述的方法是不被鼓励的,最好的方法是通过本文中所说的意图 p、 s:我不想在我的设备上安装条形码扫描仪 我已在我的项目中加入了所需的课程: 我的测试代码: 我真的不明白怎么用这种方式来做:(我真的不明白,这就是我想用的) 你知道怎么做吗 谢谢。安卓系统的设计初衷是让人们能够编写能够很好地完成某一特定任务的应用程序,而其他开发者可以在需要时使用它们。条形码扫描就是一个很好的例子。ZXing是一款很棒的扫描仪,可以让其他应用程序通
谢谢。安卓系统的设计初衷是让人们能够编写能够很好地完成某一特定任务的应用程序,而其他开发者可以在需要时使用它们。条形码扫描就是一个很好的例子。ZXing是一款很棒的扫描仪,可以让其他应用程序通过意图使用它。基本上,你告诉操作系统你想扫描条形码,ZXing说,“是的,我能做到!”他们扫描条形码并将信息返回给你。这样做的好处是你不必担心他们什么时候更新他们的东西。用户只需得到更新通知,您就可以使用最新和最好的。一个潜在的缺点是,用户的手机上有另一个应用程序,但我并不认为这是一种倒退。要这样做,您实际上只需要链接到的两个文件,然后将其放入代码中即可开始扫描:
IntentIntegrator integrator = new IntentIntegrator(yourActivity);
integrator.initiateScan();
该位从条形码扫描仪获得答案:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result
}
// else continue with any other code you need in the method
...
}
你唯一的另一个选择是把条形码扫描器的所有代码拉下来,然后把它放到你的项目中,然后弄清楚它是如何工作的,以及你需要在哪里把它带到你的应用程序中。然后,每次ZXing进行更新时,您都必须重新执行该操作。真是一团糟 安卓系统的设计初衷是让人们能够编写能够很好地完成某一特定任务的应用程序,其他开发者可以在需要时使用它们。条形码扫描就是一个很好的例子。ZXing是一款很棒的扫描仪,可以让其他应用程序通过意图使用它。基本上,你告诉操作系统你想扫描条形码,ZXing说,“是的,我能做到!”他们扫描条形码并将信息返回给你。这样做的好处是你不必担心他们什么时候更新他们的东西。用户只需得到更新通知,您就可以使用最新和最好的。一个潜在的缺点是,用户的手机上有另一个应用程序,但我并不认为这是一种倒退。要这样做,您实际上只需要链接到的两个文件,然后将其放入代码中即可开始扫描:
IntentIntegrator integrator = new IntentIntegrator(yourActivity);
integrator.initiateScan();
You can use like this.It works in Activity as well as Fragment.
Add this code in click listner of any view:
scan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(getActivity());
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setCameraId(0);
integrator.setBeepEnabled(true);
integrator.setBarcodeImageEnabled(true);
integrator.forFragment(InsuranceInfo.this).initiateScan();
System.out.println("CLick");
}
On the Acivity Result Method add this:-
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
System.out.println((intentResult.getContents()+""));
super.onActivityResult(requestCode, resultCode, data);
if (intentResult != null) {
//passing result to another Activity.
// Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentResult.getContents() + ""));
// Toast.makeText(getActivity(),"Scan Results="+(intentResult.getContents()+""),Toast.LENGTH_SHORT).show();
System.out.println((intentResult.getContents()+""));
Snackbar.make(getActivity().findViewById(android.R.id.content),
("Scan Results="+ (intentResult.getContents()+"")), Snackbar.LENGTH_LONG).show();
ScanResult= (intentResult.getContents()+"");
insurance.setText(ScanResult);
}
else {
Toast.makeText(getActivity(), " Empty Result ", Toast.LENGTH_SHORT).show();
}
}
该位从条形码扫描仪获得答案:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result
}
// else continue with any other code you need in the method
...
}
你唯一的另一个选择是把条形码扫描器的所有代码拉下来,然后把它放到你的项目中,然后弄清楚它是如何工作的,以及你需要在哪里把它带到你的应用程序中。然后,每次ZXing进行更新时,您都必须重新执行该操作。真是一团糟 谢谢:)我按照你说的做了,它可以工作,但它显示了我的应用程序第一次运行时BarcodeScanner home活动,我必须单击按钮才能到达条形码阅读器。我想改变相机的方向,从横向扫描到纵向扫描,我一直在寻找这一点,发现我应该修改条形码扫描仪的源代码,我也希望条形码扫描仪只有在一个小块。我能用这种方法做吗?谢谢。谢谢:)我照你说的做了,它工作正常,但它显示我的应用程序第一次运行时BarcodeScanner主页活动,我必须单击按钮才能到达条形码阅读器。我想改变相机的方向,从横向扫描到纵向扫描,我一直在寻找这一点,发现我应该修改条形码扫描仪的源代码,我也希望条形码扫描仪只有在一个小块。我能用这种方法做吗?非常感谢。
You can use like this.It works in Activity as well as Fragment.
Add this code in click listner of any view:
scan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(getActivity());
integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);
integrator.setCameraId(0);
integrator.setBeepEnabled(true);
integrator.setBarcodeImageEnabled(true);
integrator.forFragment(InsuranceInfo.this).initiateScan();
System.out.println("CLick");
}
On the Acivity Result Method add this:-
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
System.out.println((intentResult.getContents()+""));
super.onActivityResult(requestCode, resultCode, data);
if (intentResult != null) {
//passing result to another Activity.
// Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(intentResult.getContents() + ""));
// Toast.makeText(getActivity(),"Scan Results="+(intentResult.getContents()+""),Toast.LENGTH_SHORT).show();
System.out.println((intentResult.getContents()+""));
Snackbar.make(getActivity().findViewById(android.R.id.content),
("Scan Results="+ (intentResult.getContents()+"")), Snackbar.LENGTH_LONG).show();
ScanResult= (intentResult.getContents()+"");
insurance.setText(ScanResult);
}
else {
Toast.makeText(getActivity(), " Empty Result ", Toast.LENGTH_SHORT).show();
}
}