-2

谁能帮我在哪里可以找到完整的编译zxing条码扫描器源代码而无需安装apk文件?我看到所有安装 apk 文件的教程。

此代码无法正常工作。请帮我。

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

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

    try {
        Button scanner = (Button)findViewById(R.id.scanner);
        scanner.setOnClickListener(new OnClickListener() {

            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);
            }

        });

        Button scanner2 = (Button)findViewById(R.id.scanner2);
        scanner2.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
                startActivityForResult(intent, 0);
            }

        });

    } catch (ActivityNotFoundException anfe) {
        Log.e("onCreate", "Scanner Not Found", anfe);
    }

 }

 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
            Toast toast = Toast.makeText(this, "Content:" + contents + " Format:" +  
          format , Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP, 25, 400);
            toast.show();
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
            Toast toast = Toast.makeText(this, "Scan was Cancelled!",         
        Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP, 25, 400);
            toast.show();

        }
    }
 }
4

1 回答 1

2
  1. 下载蚂蚁http://ant.apache.org/bindownload.cgi
  2. 运行 > cmd
  3. > cd (你提取的 ant 目录)
  4. > ant -f (你的Zxing源码目录)/core/build.xml
  5. 转到(Zxing 源代码目录)/core/ 并将 core.jar 移动到您的(android 项目)/libs
  6. 在 Eclipse 中右键单击您的 Zxing 项目 > 属性 > Java 构建路径
  7. 库选项卡 > 添加 JAR 并在您的项目下选择该 core.jar

现在试试

于 2012-11-01T08:33:29.227 回答