I use Intent so that the user can select a file, and after the user has done this, I want to know what type of file is selected for the selected file.
Purpose:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
In my onActivityResult, I want to extract the path from the intent via intent.getData (), and all these are "submethods" (getScheme (), getLastPathSegment (), etc.). However, I only get Uri for the selected file.
Uris' example:
Uri: content://media/external/audio/media/15185 //This is an audiofile
Uri: content://media/external/audio/media/20 //Another audiofile
Uri: content://media/external/images/media/20577 //this is a picture
Uri: file:///storage/emulated/0/testWed%20Apr%2017%2011%3A10%3A34%20CEST%202013 //This is a file
I have seen decisions on how to get the absolute path when the user is allowed to select only images or audio. But how do I do this, I get absolutePath (the real path with the name and end of the file, for example MyPicture.jpeg), if I want to allow the user to choose from different types of files?
, , onActivityResult (int requestCode, int resultCode
String fileName = data.getData().getLastPathSegment().toString();
System.out.println("Uri: " +data.getData().toString());
File f = new File(fileName);
System.out.println("TrYinG wIWThA Da FiLE: " +f.getAbsolutePath());
System.out.println("FileNAME!!!: "+fileName);