Search code examples
androidandroid-studioqr-code

How do i generate QR code with more than 5 data information


The problem is when i try to put my string in qrgEncoder = new QRGEncoder its always error i know it wrong because i need to place all my string in one single string or hash but i dont know how were to put my hash.! I well really appreciate your respond sir thank's advance

    firstname = findViewById(R.id.firstname);
    phone = findViewById(R.id.phone);
    address = findViewById(R.id.address);
    qr = findViewById(R.id.qr);
    btn = findViewById(R.id.btn);

    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String first = firstname.getText().toString().trim();
            String phones = phone.getText().toString().trim();
            String textaddress = address.getText().toString().trim();

            if(first.length() > 0 || phones.length() > 0 || textaddress.length() > 0) {

                WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
                Display display = manager.getDefaultDisplay();
                Point point = new Point();
                display.getSize(point);
                int width = point.x;
                int height = point.y;
                int smallerDimension = width < height ? width : height;
                smallerDimension = smallerDimension * 3 / 4;

                qrgEncoder = new QRGEncoder(
                        first,phones,textaddress, null,
                        QRGContents.Type.TEXT,
                        smallerDimension);
                try {
                    bitmap = qrgEncoder.encodeAsBitmap();
                    qr.setImageBitmap(bitmap);
                } catch (WriterException e) {
                    Log.v(TAG, e.toString());
                }
            }
        }
    });
}

}


Solution

  • If I look at your code and how QRGEncoder implementations, I guess you need to concatenate your string input first, before adding it into its constructor.

    Therefore, you should call it like this:

    StringBuilder qrParam = new StringBuilder();
    qrParam.append(first);
    qrParam.append(phones);
    qrParam.append(textaddress);
    
    qrgEncoder = new QRGEncoder(
                        qrParam.toString(),
                        null,
                        QRGContents.Type.TEXT,
                        smallerDimension);