QR扫描,结果-“ com.google.android.gms.vision.barcode.Barcode@ecd6456”

时间:2018-07-16 23:29:02

标签: java android qr-code

我有问题,不知道该怎么办,目标是制作QR扫描仪,输入值,然后按OK,它应该将值存储在对象podaci中,并在其他活动中使用相同的值。

但是发生什么事,它扫描QR码,但没有显示真实值,而是显示如下内容:“ com.google.android.gms.vision.barcode.Barcode@ecd6456”,MainActivity中的对象podaci中没有存储任何值

这是我的QR课程:

unlink($attachment_file);

这是我的MainActivity类:

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.irhad.mytestapplication.data.Podaci;
import com.google.android.gms.common.api.CommonStatusCodes;
import com.google.android.gms.vision.CameraSource;
import com.google.android.gms.vision.Detector;
import com.google.android.gms.vision.barcode.Barcode;
import com.google.android.gms.vision.barcode.BarcodeDetector;

import java.io.IOException;

public class QRActivity extends AppCompatActivity{

    SurfaceView camera_preview;
    Intent main;
    EditText txtUnosUplacenog;
    TextView txtQRIspis;
    Button btnOK;
    private Podaci podaci;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.qr_activity);

        camera_preview = findViewById(R.id.camera_preview);
        txtUnosUplacenog = findViewById(R.id.txtUnosUplacenog);
        btnOK = findViewById(R.id.btnOK);
        txtQRIspis = findViewById(R.id.txtQRIspis);
        podaci = new Podaci();
        createCameraSource();
    }


    private void createCameraSource() {
        BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(this).build();
        final CameraSource cameraSource = new CameraSource.Builder(this, barcodeDetector)
                .setAutoFocusEnabled(true)
                .setRequestedPreviewSize(620, 480)
                .build();

        camera_preview.getHolder().addCallback(new SurfaceHolder.Callback() {
            @Override
            public void surfaceCreated(SurfaceHolder holder) {
                try {
                    if (ActivityCompat.checkSelfPermission(QRActivity.this,
                            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                        return;
                    }
                    cameraSource.start(camera_preview.getHolder());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}

            @Override
            public void surfaceDestroyed(SurfaceHolder holder) {
                cameraSource.stop();
            }
        });//camera_preview

        barcodeDetector.setProcessor(new Detector.Processor<Barcode>() {
            @Override
            public void release() {}

            @Override
            public void receiveDetections(Detector.Detections<Barcode> detections) {
                final SparseArray<Barcode> barcodes  = detections.getDetectedItems();
                if(barcodes.size() > 0){

                    podaci.setQrvalue(barcodes.valueAt(0).toString());
                    podaci.setUplata(Double.parseDouble(txtUnosUplacenog.getText().toString()));
                    txtQRIspis.setText(podaci.getQrvalue());
                }
            }
        });//barcodeDetector

    }//CreateCameraSource

    public void btnOK(View view){
        if(podaci.getUplata() != 0 && podaci.getQrvalue() != "")
            izadji(podaci);
    }

    public void izadji(Podaci podatak){
        main = new Intent(this, MainActivity.class);
        main.putExtra("barcode", podatak.getQrvalue() );
        main.putExtra("vrijednost", podatak.getUplata() );
        startActivity(main);
        finish();
    }

    public void izadji(View view){
        main = new Intent(this, MainActivity.class);
        startActivity(main);
        finish();
    }
}

Ps:当我握在QR码前面时,它正在改变值。 @ gr54943,@ ac45c04等...

0 个答案:

没有答案