Answer the question
In order to leave comments, you need to log in
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();
}
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question