fix NPE in MediaUtils.getMediaSize

This commit is contained in:
Conny Duck 2017-12-05 21:48:17 +01:00
parent e5516749ed
commit fbf64fa1e9
2 changed files with 4 additions and 2 deletions

View file

@ -1355,11 +1355,11 @@ public final class ComposeActivity extends BaseActivity
private void pickMedia(Uri uri, long mediaSize) { private void pickMedia(Uri uri, long mediaSize) {
ContentResolver contentResolver = getContentResolver();
if (mediaSize == MediaUtils.MEDIA_SIZE_UNKNOWN) { if (mediaSize == MediaUtils.MEDIA_SIZE_UNKNOWN) {
displayTransientError(R.string.error_media_upload_opening); displayTransientError(R.string.error_media_upload_opening);
return; return;
} }
ContentResolver contentResolver = getContentResolver();
String mimeType = contentResolver.getType(uri); String mimeType = contentResolver.getType(uri);
if (mimeType != null) { if (mimeType != null) {
String topLevelType = mimeType.substring(0, mimeType.indexOf('/')); String topLevelType = mimeType.substring(0, mimeType.indexOf('/'));

View file

@ -24,6 +24,7 @@ import android.media.MediaMetadataRetriever;
import android.media.ThumbnailUtils; import android.media.ThumbnailUtils;
import android.net.Uri; import android.net.Uri;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.Px; import android.support.annotation.Px;
@ -66,7 +67,8 @@ public class MediaUtils {
* *
* @return the size of the media or {@link MediaUtils#MEDIA_SIZE_UNKNOWN} * @return the size of the media or {@link MediaUtils#MEDIA_SIZE_UNKNOWN}
*/ */
public static long getMediaSize(ContentResolver contentResolver, Uri uri) { public static long getMediaSize(@NonNull ContentResolver contentResolver, @Nullable Uri uri) {
if(uri == null) return MEDIA_SIZE_UNKNOWN;
long mediaSize; long mediaSize;
Cursor cursor = contentResolver.query(uri, null, null, null, null); Cursor cursor = contentResolver.query(uri, null, null, null, null);
if (cursor != null) { if (cursor != null) {