- Uri selectedImageUri = data.getData();\r
- \r
- String filemanagerstring = selectedImageUri.getPath();\r
- String selectedImagePath = getPath(selectedImageUri);\r
- String filepath;\r
- \r
- if (selectedImagePath != null)\r
- filepath = selectedImagePath;\r
- else\r
- filepath = filemanagerstring;\r
- \r
- if (filepath == null) {\r
- Log.e("FileDisplay", "Couldnt resolve path to file");\r
- return;\r
+ String filepath = null;\r
+ try {\r
+ Uri selectedImageUri = data.getData();\r
+ \r
+ String filemanagerstring = selectedImageUri.getPath();\r
+ String selectedImagePath = getPath(selectedImageUri);\r
+ \r
+ if (selectedImagePath != null)\r
+ filepath = selectedImagePath;\r
+ else\r
+ filepath = filemanagerstring;\r
+ \r
+ } catch (Exception e) {\r
+ Log.e("FileDisplay", "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e);\r
+ e.printStackTrace();\r
+ \r
+ } finally {\r
+ if (filepath == null) {\r
+ Log.e("FileDisplay", "Couldnt resolve path to file");\r
+ Toast t = Toast.makeText(this, getString(R.string.filedisplay_unexpected_bad_get_content), Toast.LENGTH_LONG);\r
+ t.show();\r
+ return;\r
+ }\r