首页 > 解决方案 > 如何将 QR 码结果发送到 TextView?

问题描述

我尝试将 QR 码结果发送到 textView。虽然相机正在运行,但扫描过程不支持,虽然功能不合适。没有显示错误消息......我该怎么办?

这是我的 QrActivity .....


import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;




public class QrActivity extends AppCompatActivity   {


    /**
     * QR code declaration
     */

    Button btnscan, btnSearch;
    static TextView lblSearch;





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

        btnscan = (Button) findViewById(R.id.btnscan);
        btnscan.setClickable(false);
        btnSearch = (Button) findViewById(R.id.btnSearch);
        btnSearch.setClickable(false);
        lblSearch = (TextView) findViewById(R.id.lblSearch);




        final Activity activity = this;
        btnscan.setOnClickListener(new View.OnClickListener() {
            @Override
            public
            void onClick(View v) {
                btnscan.setClickable(true);
                IntentIntegrator integrator = new IntentIntegrator(activity);
                integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
                integrator.setPrompt("Scan");
                integrator.setCameraId(0);
                integrator.setBeepEnabled(false);
                integrator.setBarcodeImageEnabled(false);
                integrator.initiateScan();


            }


        });


    }

    /**
     * ---------------------------------------------------- QR code ----------------------------------------------------------
     */


    @Override
    protected
    void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);

        if (result != null) {

            if (result.getContents() == null) {

                Toast.makeText(this, "You cancelled the scanning", Toast.LENGTH_SHORT).show();
            } else {
                /**
                 * Qr code result
                 * */
                lblSearch.setText(result.getContents());

                // Toast.makeText(this, result.getContents(), Toast.LENGTH_SHORT).show();
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }

    /**
     *  -----------------------------------------QR scan-- Finished-------------------------------------*
     * */

标签: androidzxing

解决方案


推荐阅读