I need to get the name and extension of a file that I need to upload. I let the user select the file using an Intent call and get the URI as follows:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
/* stuff */
Uri uri = data.getData();
String filePath = data.getData().getPath();
Log.d("filePath ",filePath);
Log.d("URI ", uri.toString());
String fileName = (new File(filePath)).getName();
Log.d("fileName ",fileName);
but the results are as follows:
com.blah.blah D/URI: content://com.android.providers.downloads.documents/document/354
com.blah.blah D/filePath: /document/354
com.blah.blah D/fileName: 354
the name of the file isn't even 354! its a PDF file (say "Bus e-Ticket.pdf" or "Xender.apk")
String fileName = (new File(filePath)).getAbsolutePath();
also yields the same.
how can i get the file name/exstension on disk?