From b22d863c362bb6492240700c0f69f1a5d926f46b Mon Sep 17 00:00:00 2001 From: steckbrief Date: Tue, 3 Nov 2015 21:09:36 +0100 Subject: Implements FS#26: Introduction of dialog to choose whether to resize a picture or not --- .../conversationsplus/utils/FileHelper.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java (limited to 'src/main/java/de/thedevstack/conversationsplus/utils') diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java new file mode 100644 index 00000000..3384b54e --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java @@ -0,0 +1,43 @@ +package de.thedevstack.conversationsplus.utils; + +import android.database.Cursor; +import android.net.Uri; +import android.provider.MediaStore; + +import de.thedevstack.conversationsplus.ConversationsPlusApplication; + +/** + * Created by tzur on 30.10.2015. + */ +public final class FileHelper { + + /** + * Get the real path from an Uri. + * @param uri the uri to convert to the real path + * @return the real path or null + */ + public static String getRealPathFromUri(Uri uri) { + String path = null; + if (uri.getScheme().equals("file")) { + return uri.getPath(); + } else if (uri.toString().startsWith("content://media/")) { + String[] projection = {MediaStore.MediaColumns.DATA}; + Cursor metaCursor = ConversationsPlusApplication.getInstance().getContentResolver().query(uri, + projection, null, null, null); + if (metaCursor != null) { + try { + if (metaCursor.moveToFirst()) { + path = metaCursor.getString(0); + } + } finally { + metaCursor.close(); + } + } + } + return path; + } + + private FileHelper() { + // Utility class - do not instantiate + } +} -- cgit v1.2.3