ДЕЯТЕЛЬНОСТЬ
Код: Выделить всё
ActivityResultLauncher activityResultLauncher;
buttonSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent ix = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
activityResultLauncher.launch(ix);
}
});
Код: Выделить всё
activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
@Override
public void onActivityResult(ActivityResult result) {
Bundle exstra = result.getData().getExtras();
Uri imageUri;
Bitmap bitmap = (Bitmap) exstra.get("data");
WeakReference result1 = new WeakReference(Bitmap.createScaledBitmap(bitmap,
bitmap.getHeight(),bitmap.getWidth(),false).copy(Bitmap.Config.RGB_565,true));
Bitmap bmP = result1.get();
imageUri = saveImage(bmP, UploadCamera.this);
imgT.setImageURI(imageUri);
lv_txt.setText(""+imageUri);
}
});
Код: Выделить всё
private Uri saveImage(Bitmap img, Context context) {
File imagesFolder = new File(context.getCacheDir(),"photome");
Uri uris = null;
try{
imagesFolder.mkdir();
File file = new File(imagesFolder,"captureimage.jpg");
FileOutputStream stream = new FileOutputStream(file);
img.compress(Bitmap.CompressFormat.JPEG,100,stream);
stream.flush();
stream.close();
uris = FileProvider.getUriForFile(context.getApplicationContext(),"",file);
} catch (FileNotFoundException e){
} catch (IOException e){
}
return uris;
}
добавление поставщика запросы в манифестах
Код: Выделить всё
android:authorities="${applicationId}.provider"
android:name="androidx.core.content.FileProvider"
android:exported="true"
android:grantUriPermissions="true">
Подробнее здесь: https://stackoverflow.com/questions/782 ... oid-studio
Мобильная версия