diff options
Diffstat (limited to 'src/main/java/de')
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/FileBackend.java | 11 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/FileUtils.java | 15 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 143505e9a..b4a758b07 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -578,8 +578,7 @@ public class FileBackend { public static Uri getUriForFile(Context context, File file) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { - String packageId = context.getPackageName(); - return FileProvider.getUriForFile(context, packageId + FILE_PROVIDER, file); + return FileProvider.getUriForFile(context, getAuthority(context), file); } catch (IllegalArgumentException e) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { throw new SecurityException(e); @@ -592,6 +591,10 @@ public class FileBackend { } } + public static String getAuthority(Context context) { + return context.getPackageName() + FILE_PROVIDER; + } + public static Uri getIndexableTakePhotoUri(Uri original) { if ("file".equals(original.getScheme())) { return original; @@ -776,9 +779,7 @@ public class FileBackend { input = rotate(input, getRotation(image)); return cropCenterSquare(input, size); } - } catch (SecurityException e) { - return null; // happens for example on Android 6.0 if contacts permissions get revoked - } catch (FileNotFoundException e) { + } catch (FileNotFoundException | SecurityException e) { return null; } finally { close(is); diff --git a/src/main/java/de/pixart/messenger/utils/FileUtils.java b/src/main/java/de/pixart/messenger/utils/FileUtils.java index e37f0d44a..ce5bcc53b 100644 --- a/src/main/java/de/pixart/messenger/utils/FileUtils.java +++ b/src/main/java/de/pixart/messenger/utils/FileUtils.java @@ -14,8 +14,10 @@ import android.util.Log; import android.webkit.MimeTypeMap; import java.io.File; +import java.util.List; import de.pixart.messenger.Config; +import de.pixart.messenger.persistance.FileBackend; public class FileUtils { @@ -92,7 +94,13 @@ public class FileUtils { // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { Log.d(Config.LOGTAG, "FileUtils is media store"); - String path = getDataColumn(context, uri, null, null); + List<String> segments = uri.getPathSegments(); + String path; + if (FileBackend.getAuthority(context).equals(uri.getAuthority()) && segments.size() > 1 && segments.get(0).equals("external")) { + path = Environment.getExternalStorageDirectory().getAbsolutePath() + uri.getPath().substring(segments.get(0).length() + 1); + } else { + path = getDataColumn(context, uri, null, null); + } if (path != null) { File file = new File(path); if (!file.canRead()) { @@ -120,15 +128,12 @@ public class FileUtils { * @param selectionArgs (Optional) Selection arguments used in the query. * @return The value of the _data column, which is typically a file path. */ - public static String getDataColumn(Context context, Uri uri, String selection, - String[] selectionArgs) { - + public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; - try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { |