1

So my problem is that I need pick image from gallery and then move him into my file and then save this path(path to my file) in string. Is it possible to do such thing? I'm beginner and really need this. This is my code which works on same issue but with camera.

    private void openGallery(){
   Intent vyber = new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.INTERNAL_CONTENT_URI);
            File file2 = getFile2();
            vyber.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(file2));
            startActivityForResult(vyber , PICK_IMAGE);
        }


    }

    private File getFile2()
    {
        File folder = new File("sdcard/MyDirectory");

        if (!folder.exists())
        {
            folder.mkdir();
        }

        File image_file2 = new File(folder,kod_useku_komunikaceS+"_gallery_image.jpg");
        return image_file2;
    }


@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){   
 if (resultCode == RESULT_OK && requestCode == PICK_IMAGE){
                String cesta = "sdcard/MyDirectory/"+kod_useku_komunikaceS+"_gallery_image.jpg";
                path_gallery = cesta;
                imageView_VyberFotku.setImageDrawable(Drawable.createFromPath(cesta));
J Sol
  • 67
  • 7
  • I think your answer is here [http://stackoverflow.com/questions/25841235/how-to-get-file-path-in-onactivityresult-in-android-4-4][1] – Mohammadhossein.Saeb.Shabani Aug 09 '16 at 19:41
  • Actually my API is 16 and this required 19. Is there any easy way to solve my problem? – J Sol Aug 09 '16 at 19:48
  • I tried that solution and it's not working this is what i wrote into onActivityResult `if (resultCode == RESULT_OK && requestCode == PICK_IMAGE){ Uri selectedImageUri = data.getData(); System.out.println(selectedImageUri.toString()); // MEDIA GALLERY // String cesta = imageUri_vybrana = data.getData(); if (imageUri_vybrana == null) System.out.println("imageUri_vybrana is null"); String cesta = ImageFilePath.getPath(context,imageUri_vybrana); Toast.makeText(MainActivity.this,cesta, Toast.LENGTH_SHORT).show();` – J Sol Aug 09 '16 at 20:08
  • Do you have any other ideas please? – J Sol Aug 09 '16 at 20:47

0 Answers0