Let MediaScannerConnection to scan the downloaded Reddit videos after downloading to make the video shows up in WhatsApp.

This commit is contained in:
Alex Ning 2020-06-08 11:50:34 +08:00
parent 580f9d2459
commit 4c762f4bd9

View File

@ -13,6 +13,7 @@ import android.media.MediaCodec;
import android.media.MediaExtractor; import android.media.MediaExtractor;
import android.media.MediaFormat; import android.media.MediaFormat;
import android.media.MediaMuxer; import android.media.MediaMuxer;
import android.media.MediaScannerConnection;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
@ -225,12 +226,17 @@ public class DownloadRedditVideoService extends Service {
} }
EventBus.getDefault().post(new DownloadRedditVideoEvent(false)); EventBus.getDefault().post(new DownloadRedditVideoEvent(false));
} else { } else {
Intent intent = new Intent(); MediaScannerConnection.scanFile(
intent.setAction(android.content.Intent.ACTION_VIEW); this, new String[]{destinationFileUri.toString()}, null,
intent.setDataAndType(destinationFileUri, "video/*"); (path, uri) -> {
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); Intent intent = new Intent();
updateNotification(R.string.downloading_reddit_video_finished, fileName, pendingIntent); intent.setAction(android.content.Intent.ACTION_VIEW);
EventBus.getDefault().post(new DownloadRedditVideoEvent(true)); intent.setDataAndType(destinationFileUri, "video/*");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
updateNotification(R.string.downloading_reddit_video_finished, fileName, pendingIntent);
EventBus.getDefault().post(new DownloadRedditVideoEvent(true));
}
);
} }
stopForeground(false); stopForeground(false);
} }