android掃描商品條碼

來源:互聯網
上載者:User
android掃描商品條碼

剛才寫的編寫最簡單的android掃描條碼功能,只能掃描qr二維碼。如果要掃描普通的商品條碼,需要在該程式上座一點兒修改。

介面的改動:

掃描條碼時的效果:

顯示掃描結果(識別速度明顯低於二維碼):

代碼的改動:

package com.easymorse;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ShowBarcodeActivity extends Activity {

private Button button;

private Button button2;

private TextView textView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

this.button = (Button) this.findViewById(R.id.Button01);
this.button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(
“com.google.zxing.client.android.SCAN”);
intent.putExtra(“SCAN_MODE”, “QR_CODE_MODE”);
startActivityForResult(intent, 0);
}
});

this.button2 = (Button) this.findViewById(R.id.Button02);
this.button2.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(
“com.google.zxing.client.android.SCAN”);
intent.putExtra(“SCAN_MODE”, “EAN_13″);
startActivityForResult(intent, 0);
}
});

this.textView = (TextView) this.findViewById(R.id.hello);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != 0) {
return;
}

this.textView.setText(data.getStringExtra(“SCAN_RESULT”));
}
}

寫完這個樣本,才發現其實現在不需要寫:

intent.putExtra(“SCAN_MODE”, “QR_CODE_MODE”);

zxing現在的庫可以自動的識別是哪種編碼。如果寫了,反而是指定類型,不能識別其他類型的編碼。實際上,上面的:

intent.putExtra(“SCAN_MODE”, “EAN_13″);

寫的不對。具體常量參數,見:

http://zxing.org/w/docs/javadoc/constant-values.html

上面的內容不修改了,正確的原始碼共用在google code的svn中,見:

http://easymorse.googlecode.com/svn/tags/barcode.proto.0.1.0/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.