2017-12-01 11:02:30 -08:00
|
|
|
package org.thoughtcrime.securesms.util;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.core.content.FileProvider;
|
2017-12-01 11:02:30 -08:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
public class FileProviderUtil {
|
|
|
|
|
2019-11-27 08:53:57 +11:00
|
|
|
private static final String AUTHORITY = "network.loki.securesms.fileprovider";
|
2017-12-01 11:02:30 -08:00
|
|
|
|
|
|
|
public static Uri getUriFor(@NonNull Context context, @NonNull File file) {
|
2019-01-13 19:08:33 -08:00
|
|
|
if (Build.VERSION.SDK_INT >= 24) return FileProvider.getUriForFile(context, AUTHORITY, file);
|
|
|
|
else return Uri.fromFile(file);
|
2017-12-01 11:02:30 -08:00
|
|
|
}
|
|
|
|
|
2018-09-12 17:47:41 -05:00
|
|
|
public static boolean isAuthority(@NonNull Uri uri) {
|
|
|
|
return AUTHORITY.equals(uri.getAuthority());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean delete(@NonNull Context context, @NonNull Uri uri) {
|
|
|
|
if (AUTHORITY.equals(uri.getAuthority())) {
|
|
|
|
return context.getContentResolver().delete(uri, null, null) > 0;
|
|
|
|
}
|
|
|
|
return new File(uri.getPath()).delete();
|
|
|
|
}
|
2017-12-01 11:02:30 -08:00
|
|
|
}
|