1

People would like to know how I share an image generated within the app,

in the app's scope the person writing in the text view it captures and generates an image would like to share that image via whats or email.

private void gerarQRCode() {

    String texto = edtTexto.getText().toString();
    MultiFormatWriter multiFormatWriter = new MultiFormatWriter();

    try {

        BitMatrix bitmatrix = multiFormatWriter.encode(texto, BarcodeFormat.QR_CODE, 2000, 2000);
        BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
        Bitmap bitmap = barcodeEncoder.createBitmap(bitmatrix);
        ivQRCode.setImageBitmap(bitmap);
    } catch (WriterException e) {

        e.printStackTrace();

    }
}
Almir Kubo
  • 11
  • 3

1 Answers1

2

Step #1: Write the Bitmap to a file on internal storage, using the compress() method

Step #2: Set up FileProvider to be able to serve files from where you are storing the bitmap

Step #3: Use FileProvider.getUriForFile() to get a Uri representing that bitmap

Step #4: Use ACTION_SEND to offer that bitmap to other apps for sharing purposes

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491