1. Manuel Dahmen's Avatar
    Hello,

    I can't find a way to select a file from filesystem (image) in a ImageView.

    I do it like this:
    private void startCreation(){

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("file/*.*");
    intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    Intent intent2 = Intent.createChooser(intent, "Choose a file");
    System.out.println(intent2);
    startActivityForResult(intent2, 9999);
    }
    @override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 9999 && resultCode==Activity.RESULT_OK) {
    String choose_directoryData = data.getDataString();
    Bitmap photo = null;
    try {
    System.out.println(choose_directoryData);
    photo = BitmapFactory.decodeStream(new FileInputStream(choose_directoryData));
    currentFile = new File(choose_directoryData);
    fillGallery(photo, data);
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    } else {
    Toast.makeText(this, "Error request "+requestCode, Toast.LENGTH_LONG).show();
    }
    }

    W/System.err: java.io.FileNotFoundException: content:/com.android.externalstorage.documents/document/primary%3APictures%2FFeatureApp%2Fdata%2FMyImage_1.jpg: open failed:

    File is returned in the Uri form and I can't open it.

    Thank you.
    11-22-2021 04:42 AM

Similar Threads

  1. Replies: 2
    Last Post: 11-22-2021, 11:32 PM
  2. Android 11 Whatsapp Media IssueAfter upgrade
    By Android Central Question in forum Ask a Question
    Replies: 2
    Last Post: 11-22-2021, 11:19 PM
  3. Replies: 26
    Last Post: 11-22-2021, 10:57 PM
  4. Samsung themes on Android 12
    By mesocyclone30 in forum Samsung Galaxy S21 & S21+ & S21 Ultra
    Replies: 3
    Last Post: 11-22-2021, 04:40 PM
  5. Replies: 1
    Last Post: 11-21-2021, 07:18 PM
LINK TO POST COPIED TO CLIPBOARD