O
O
oyshomusic2021-01-18 12:18:34
Android
oyshomusic, 2021-01-18 12:18:34

How to save image in application files?

Good afternoon, dear reader!
There is a code that generates a QR code:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        etInput = findViewById(R.id.et_input);
        btGenerate = findViewById(R.id.bt_generate);
        ivOutput = findViewById(R.id.iv_output);

        btGenerate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String sText = etInput.getText().toString().trim();
                MultiFormatWriter writer = new MultiFormatWriter();
                try {
                    BitMatrix matrix = writer.encode(sText, BarcodeFormat.QR_CODE,
                            350, 350);
                    BarcodeEncoder encoder = new BarcodeEncoder();
                    Bitmap bitmap = encoder.createBitmap(matrix);
                    ivOutput.setImageBitmap(bitmap);
                    InputMethodManager manager = (InputMethodManager) getSystemService(
                            Context.INPUT_METHOD_SERVICE
                    );
                    manager.hideSoftInputFromWindow(etInput.getApplicationWindowToken()
                    ,0);
                    btGenerate.setVisibility(View.INVISIBLE);
                    etInput.setVisibility(View.INVISIBLE);
                } catch (WriterException e) {
                    e.printStackTrace();
                }
            }
        });

    }

I need to save the image to the application files after generation and network it to the widget when the application is reloaded. If someone came across, tell me with an example of my code. I will be very grateful!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question