Вот как я беру изображение и устанавливаю байты в список массивов строк:
Код: Выделить всё
activityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if(result.getResultCode() == RESULT_OK && result != null)
{
Uri uploadfileuri = result.getData().getData();
InputStream inputStream = null;//You can get an inputStream using any IO API
if(uploadfileuri != null){
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
inputStream = getApplicationContext().getContentResolver().openInputStream(uploadfileuri);
byte[] buffer = new byte[8192];
int bytesRead;
Base64OutputStream outputBase64 = new Base64OutputStream(output, Base64.DEFAULT);
try {
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputBase64.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
}
outputBase64.close();
String strBytes = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
strBytes = java.util.Base64.getEncoder().encodeToString(buffer);
}
strBytesImages.add(strBytes);
profileImageUri.add(uploadfileuri);
baseAdapter.notifyDataSetChanged();
} catch (Exception ex) {
}
}
}
});
Код: Выделить всё
View row = convertView;
ViewHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.image = (ImageView) row.findViewById(R.id.profileImage);
holder.text = (TextView) row.findViewById(R.id.profileDeleteTV);
holder.text.setPaintFlags(holder.text.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
byte[] imageByte = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
imageByte = Base64.getDecoder().decode(data.get(position).getBytes());
}
Bitmap bitmap = BitmapFactory.decodeByteArray(imageByte, 0, imageByte.length);
holder.image.setImageBitmap(bitmap);
Подробнее здесь: https://stackoverflow.com/questions/798 ... d-then-con
Мобильная версия