I'm working on my android app and i have a problem. I need to get the file path for. Below you can see my code
private void pickStorageForMap()
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("application/pdf");
startActivityForResult(intent, PICK_MAP_GPX);
}
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_MAP_GPX && resultCode == RESULT_OK) {
if(data.getData() != null) {
Uri uri = data.getData();
String path = uri.getPath();
Toast.makeText(mContext, "Type "+ path, Toast.LENGTH_SHORT).show();
}else
{
Toast.makeText(mContext, "There is no file", Toast.LENGTH_LONG).show();
}
}
}
The problem is that the file I select is not a Mime type, I need to select a file with the gpx extension. And to check if the file has the extension I need, I want to extract its name from the path. But the problem is that when I get the path, then instead of:
"/external/iamges/media/map.gpx"
I get
"/external/images/media/292021"
Can I somehow solve this problem so that instead of numbers at the end there is a file name?