mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 11:05:25 +00:00
32 lines
961 B
Java
32 lines
961 B
Java
package org.thoughtcrime.securesms.util;
|
|
|
|
|
|
import android.content.Context;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.v4.content.FileProvider;
|
|
|
|
import java.io.File;
|
|
|
|
public class FileProviderUtil {
|
|
|
|
private static final String AUTHORITY = "network.loki.securesms.fileprovider";
|
|
|
|
public static Uri getUriFor(@NonNull Context context, @NonNull File file) {
|
|
if (Build.VERSION.SDK_INT >= 24) return FileProvider.getUriForFile(context, AUTHORITY, file);
|
|
else return Uri.fromFile(file);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|