aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2022-06-11 13:01:33 +0000
committerDocile-Alligator <chineseperson5@gmail.com>2022-06-11 13:01:33 +0000
commitb6162c14965b8bc0b379771f47aa1abba7b8e80d (patch)
treea3551e9f1ea38e8d14ced9479da1349423820189
parent33c473824bb3da4abfd7f346e53db2648f19395f (diff)
downloadinfinity-for-reddit-b6162c14965b8bc0b379771f47aa1abba7b8e80d.tar
infinity-for-reddit-b6162c14965b8bc0b379771f47aa1abba7b8e80d.tar.gz
infinity-for-reddit-b6162c14965b8bc0b379771f47aa1abba7b8e80d.tar.bz2
infinity-for-reddit-b6162c14965b8bc0b379771f47aa1abba7b8e80d.tar.lz
infinity-for-reddit-b6162c14965b8bc0b379771f47aa1abba7b8e80d.tar.xz
infinity-for-reddit-b6162c14965b8bc0b379771f47aa1abba7b8e80d.tar.zst
infinity-for-reddit-b6162c14965b8bc0b379771f47aa1abba7b8e80d.zip
Fix app crashes when deleting media from notification.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/DownloadedMediaDeleteActionBroadcastReceiver.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/DownloadedMediaDeleteActionBroadcastReceiver.java b/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/DownloadedMediaDeleteActionBroadcastReceiver.java
index 22e2e2f1..323c78eb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/DownloadedMediaDeleteActionBroadcastReceiver.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/DownloadedMediaDeleteActionBroadcastReceiver.java
@@ -8,13 +8,27 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import androidx.documentfile.provider.DocumentFile;
+
+import java.io.File;
+
public class DownloadedMediaDeleteActionBroadcastReceiver extends BroadcastReceiver {
public static final String EXTRA_NOTIFICATION_ID = "ENI";
@Override
public void onReceive(Context context, Intent intent) {
Uri mediaUri = intent.getData();
if (mediaUri != null) {
- context.getContentResolver().delete(mediaUri, null, null);
+ try {
+ context.getContentResolver().delete(mediaUri, null, null);
+ } catch (Exception e) {
+ DocumentFile file = DocumentFile.fromSingleUri(context, mediaUri);
+ if (file != null) {
+ if (!file.delete()) {
+ new File(mediaUri.toString()).delete();
+ }
+ }
+ }
+
}
NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);