get real file name for files shared from Conversations
This commit is contained in:
parent
93f405d9a1
commit
be5e39a440
|
@ -536,8 +536,7 @@ public class FileBackend {
|
||||||
public static Uri getUriForFile(Context context, File file) {
|
public static Uri getUriForFile(Context context, File file) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || Config.ONLY_INTERNAL_STORAGE) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || Config.ONLY_INTERNAL_STORAGE) {
|
||||||
try {
|
try {
|
||||||
String packageId = context.getPackageName();
|
return FileProvider.getUriForFile(context, getAuthority(context), file);
|
||||||
return FileProvider.getUriForFile(context, packageId + FILE_PROVIDER, file);
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
throw new SecurityException(e);
|
throw new SecurityException(e);
|
||||||
|
@ -550,6 +549,10 @@ public class FileBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getAuthority(Context context) {
|
||||||
|
return context.getPackageName() + FILE_PROVIDER;
|
||||||
|
}
|
||||||
|
|
||||||
public static Uri getIndexableTakePhotoUri(Uri original) {
|
public static Uri getIndexableTakePhotoUri(Uri original) {
|
||||||
if (Config.ONLY_INTERNAL_STORAGE || "file".equals(original.getScheme())) {
|
if (Config.ONLY_INTERNAL_STORAGE || "file".equals(original.getScheme())) {
|
||||||
return original;
|
return original;
|
||||||
|
@ -727,9 +730,7 @@ public class FileBackend {
|
||||||
input = rotate(input, getRotation(image));
|
input = rotate(input, getRotation(image));
|
||||||
return cropCenterSquare(input, size);
|
return cropCenterSquare(input, size);
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (FileNotFoundException | SecurityException e) {
|
||||||
return null; // happens for example on Android 6.0 if contacts permissions get revoked
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
close(is);
|
close(is);
|
||||||
|
|
|
@ -11,6 +11,9 @@ import android.provider.DocumentsContract;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.persistance.FileBackend;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils {
|
||||||
|
|
||||||
|
@ -83,7 +86,13 @@ public class FileUtils {
|
||||||
}
|
}
|
||||||
// MediaStore (and general)
|
// MediaStore (and general)
|
||||||
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||||
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) {
|
if (path != null) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
if (!file.canRead()) {
|
if (!file.canRead()) {
|
||||||
|
@ -111,7 +120,7 @@ public class FileUtils {
|
||||||
* @return The value of the _data column, which is typically a file path.
|
* @return The value of the _data column, which is typically a file path.
|
||||||
*/
|
*/
|
||||||
public static String getDataColumn(Context context, Uri uri, String selection,
|
public static String getDataColumn(Context context, Uri uri, String selection,
|
||||||
String[] selectionArgs) {
|
String[] selectionArgs) {
|
||||||
|
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
final String column = "_data";
|
final String column = "_data";
|
||||||
|
@ -120,12 +129,12 @@ public class FileUtils {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,null);
|
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
final int column_index = cursor.getColumnIndexOrThrow(column);
|
final int column_index = cursor.getColumnIndexOrThrow(column);
|
||||||
return cursor.getString(column_index);
|
return cursor.getString(column_index);
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
|
|
Loading…
Reference in a new issue