aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/utils
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-11-03 21:33:14 +0100
committersteckbrief <steckbrief@chefmail.de>2015-11-03 21:33:14 +0100
commit0575767152abc391fd1d0241d9cbae154236df70 (patch)
treed4530ebbdb2de9ed0f0c41eb008a712edba6d7f6 /src/main/java/de/thedevstack/conversationsplus/utils
parent389e3d4f0f5116f5ea22cc7c5e8cec1e6c791e3a (diff)
parentb22d863c362bb6492240700c0f69f1a5d926f46b (diff)
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/utils')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/FileHelper.java43
1 files changed, 43 insertions, 0 deletions
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 <code>null</code>
+ */
+ 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
+ }
+}