You need to implement such a chip: the application asks you to select an image in the files, using installed programs (for example, "My Files"), then to pull out its full path from the file. This I saw ... Well, in the alarm clock, VC application, etc.

How to implement it?

At first, I just wanted to get a list of files in the ListView using the File class, but I realized that it would not be convenient for the user. There should be an alternative like in other programs.

    3 answers 3

    Suppose you want to get a picture from the gallery.

    Then we write the following:

    Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, 1); 

    This will launch the gallery. When you select a photo, the onActivityResult () method will work, so we override it:

     protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch(requestCode) { case 1: { if (resultCode == RESULT_OK) { Uri chosenImageUri = data.getData(); } break; } } } 

    In the chosenImageUri object there is a path to the gallery object, it looks like this: media / xcvbcxvb / sdfadf / xvb / 12332

    In order to get the path to the SD card from this nonsense we write:

     final Cursor cursor = getContentResolver().query( chosenImageUri, null, null, null, null ); cursor.moveToFirst(); final String filePath = cursor.getString(0); cursor.close(); 

    Voila, in the filePath object is the full path to the file we need

    • I never managed to get the full path to the file with your code - gc986
    • Please tell me how to select other files. For example, from the download folder, etc. - Engineman

    You can get a link like this

    • Please give a more detailed answer. - 0xdb
     Cursor cursor = context.getContentResolver().query(selectedImage, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null); cursor.moveToFirst(); final String imageFilePath = cursor.getString(0); // Link to the image