You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/09/09 22:10:52 UTC

git commit: [CB-4764] Remove reference to DirectoryManager from Capture.java

Updated Branches:
  refs/heads/dev 84027b269 -> cac34ea50


[CB-4764] Remove reference to DirectoryManager from Capture.java


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/commit/cac34ea5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/tree/cac34ea5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/diff/cac34ea5

Branch: refs/heads/dev
Commit: cac34ea509ea161c8ce40b56883d88e28fdad86e
Parents: 84027b2
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Sep 9 16:01:28 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Sep 9 16:10:43 2013 -0400

----------------------------------------------------------------------
 src/android/Capture.java | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture/blob/cac34ea5/src/android/Capture.java
----------------------------------------------------------------------
diff --git a/src/android/Capture.java b/src/android/Capture.java
index 1f00a82..bea115b 100644
--- a/src/android/Capture.java
+++ b/src/android/Capture.java
@@ -24,11 +24,11 @@ import java.io.IOException;
 import java.io.OutputStream;
 
 import android.os.Build;
+
 import org.apache.cordova.CallbackContext;
 import org.apache.cordova.CordovaPlugin;
 import org.apache.cordova.LOG;
 import org.apache.cordova.PluginResult;
-import org.apache.cordova.DirectoryManager;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -198,6 +198,24 @@ public class Capture extends CordovaPlugin {
         this.cordova.startActivityForResult((CordovaPlugin) this, intent, CAPTURE_AUDIO);
     }
 
+    private String getTempDirectoryPath() {
+        File cache = null;
+
+        // SD Card Mounted
+        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+            cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
+                    "/Android/data/" + cordova.getActivity().getPackageName() + "/cache/");
+        }
+        // Use internal storage
+        else {
+            cache = cordova.getActivity().getCacheDir();
+        }
+
+        // Create the cache directory if it doesn't exist
+        cache.mkdirs();
+        return cache.getAbsolutePath();
+    }
+
     /**
      * Sets up an intent to capture images.  Result handled by onActivityResult()
      */
@@ -208,7 +226,7 @@ public class Capture extends CordovaPlugin {
         Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
 
         // Specify file so that large image is captured and returned
-        File photo = new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), "Capture.jpg");
+        File photo = new File(getTempDirectoryPath(), "Capture.jpg");
         intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
 
         this.cordova.startActivityForResult((CordovaPlugin) this, intent, CAPTURE_IMAGE);
@@ -276,7 +294,7 @@ public class Capture extends CordovaPlugin {
                             return;
                         }
                     }
-                    FileInputStream fis = new FileInputStream(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/Capture.jpg");
+                    FileInputStream fis = new FileInputStream(getTempDirectoryPath() + "/Capture.jpg");
                     OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
                     byte[] buffer = new byte[4096];
                     int len;