Skip to content

Commit

Permalink
Prevent the app from crashing when file mime type is null (#2582)
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum committed Feb 20, 2019
1 parent 50082e3 commit 4e83c1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,12 @@ public static String getMimeType(String filePath) {
}

public static String getMimeTypeFromUri(final Context context, final Uri uri) {
ContentResolver cR = context.getContentResolver();
return cR.getType(uri);
try {
ContentResolver cR = context.getContentResolver();
return cR.getType(uri);
} catch (Exception e) {
return "application/octet-stream";
}
}

public static void deleteTempFiles(final File dir) {
Expand Down
13 changes: 8 additions & 5 deletions android/app/src/main/java/com/mattermost/share/ShareModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,15 @@ public WritableArray processIntent() {
map.putString("value", text);

type = RealPathUtil.getMimeTypeFromUri(currentActivity, uri);
if (type.equals("image/*")) {
type = "image/jpeg";
} else if (type.equals("video/*")) {
type = "video/mp4";
if (type != null) {
if (type.equals("image/*")) {
type = "image/jpeg";
} else if (type.equals("video/*")) {
type = "video/mp4";
}
} else {
type = "application/octet-stream";
}

map.putString("type", type);
items.pushMap(map);
}
Expand Down

0 comments on commit 4e83c1f

Please sign in to comment.