Permission Denial beim benutzen einer URI in android studio java?

1 Antwort

Probiere mal

public class ItemActivity extends AppCompatActivity {
    private ActivityResultLauncher<Intent> galleryLauncher =
            registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
                    result -> {
                        if (result.getResultCode() == RESULT_OK && result.getData() != null) {
                            Uri imageUri = result.getData().getData();
                            try {


                                // Speichern des Bildpfads in den SharedPreferences
                                SharedPreferences sharedPreferences = getPreferences(Context.MODE_PRIVATE);
                                SharedPreferences.Editor editor = sharedPreferences.edit();
                                editor.putString("image_button_" + tempIMGID, imageUri.toString()); // itemID imageBtn2.getId()
                                editor.apply();


                                finish();
                                startActivity(getIntent());


                            } catch (Exception e) {
                                e.printStackTrace();
                            }


                        }
                    });


    // ...


    if (!imagePath.equals("")) {
        Uri imageUri = Uri.parse(imagePath);
        try {
            InputStream inputStream = getContentResolver().openInputStream(imageUri);
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
      
            int width = 110;
            int height = 100;
            Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
      
            imageBtn2.setImageBitmap(scaledBitmap);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


TEXpIoder 
Fragesteller
 23.05.2023, 17:25

Sieht Plausibel aus. Ich werde es gleich mal probieren vielen dank jetzt schonmal für die Antwort

0