fix NPE in MediaUtils.getMediaSize

main
Conny Duck 7 years ago
parent 46dce4293a
commit 21568e69a6
  1. 2
      app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java
  2. 4
      app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.java

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

@ -24,6 +24,7 @@ import android.media.MediaMetadataRetriever;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.provider.OpenableColumns;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.Px;
@ -66,7 +67,8 @@ public class MediaUtils {
*
* @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;
Cursor cursor = contentResolver.query(uri, null, null, null, null);
if (cursor != null) {

Loading…
Cancel
Save