mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-28 11:58:23 +01:00
Fix app crashes when deleting media from notification.
This commit is contained in:
parent
33c473824b
commit
b6162c1496
@ -8,13 +8,27 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import androidx.documentfile.provider.DocumentFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class DownloadedMediaDeleteActionBroadcastReceiver extends BroadcastReceiver {
|
public class DownloadedMediaDeleteActionBroadcastReceiver extends BroadcastReceiver {
|
||||||
public static final String EXTRA_NOTIFICATION_ID = "ENI";
|
public static final String EXTRA_NOTIFICATION_ID = "ENI";
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Uri mediaUri = intent.getData();
|
Uri mediaUri = intent.getData();
|
||||||
if (mediaUri != null) {
|
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);
|
NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
Loading…
Reference in New Issue
Block a user