简体   繁体   English

在Android的ZXing中访问QR码坐标

[英]Access to QR code coordinate in ZXing on Android

I'm developing a ZXing project in Eclipse: 我正在Eclipse中开发ZXing项目:

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button b=(Button)findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View view)
        {
        Log.d("test", "button works!");
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);


         b1 = (Button)findViewById(R.id.button111);

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


                    Log.i("xZing", "contents: "+contents+" format: "+format);
                    // Handle successful scan
                } 
                else if (resultCode == RESULT_CANCELED)
                {
                    // Handle cancel
                    Log.i("xZing", "Cancelled");
                }
            }

I found the finder pattern coordinates are in the Detector class ( getTopLeft and getTopRight and getBottomLeft ) but when I want to access them I'm facee with errors in the code. 我发现查找程序模式坐标位于Detector类( getTopLeftgetTopRightgetBottomLeft )中,但是当我要访问它们时,我遇到了代码错误。 I don't know how I can access these variables. 我不知道如何访问这些变量。 For example, I define a public static FinderPattern topLeft1 in the Detector class and in the processFinderPatternInfo method I add topLeft1=topLeft . 例如,我在Detector类中定义了一个public static FinderPattern topLeft1 ,并且在processFinderPatternInfo方法中添加了topLeft1=topLeft After startActivity for the result I add: startActivity结果之后,我添加:

float m1=Detector.topLeft1.x;
 m2=Detector.topLeft1.y;
 b.setText("(x,y)="+m1+","+m2); 

but when I run the program and click the button to scan: I get: 但是当我运行程序并单击按钮进行扫描时:我得到:

unfortunately zxing has stopped 不幸的是zxing已经停止了

I need 10 reputation to post an image and I can't post logcat image :-( Can any one help me soon? Thanks a lot 我需要10点信誉才能发布图像,但我不能发布logcat图像:-(谁能尽快帮助我吗?非常感谢

I solved my problem.I must write OnActivityResult class out of OnCreate Method! 我解决了我的问题,我必须使用OnCreate方法编写OnActivityResult类! That's all! 就这样! thank you all. 谢谢你们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM