forked from github/cordova-android
Issue #156: Camera.DestinationType.FILE_URI on Android not conforming to API Spec
Instead of capturing the orginal image to /sdcard/Pic.jpg or /sdcard/Capture.jpg we detect if the SD card is mounted. If mounted the file is placed in the apps temp directory at: /sdcard/Android/data/{package name}/cache/ If the SD card is not mounted we default to internal storage at: /data/data/{package name}/cache/
This commit is contained in:
parent
53410781e4
commit
eb0e0d9d11
@ -28,6 +28,7 @@ import android.graphics.Bitmap.CompressFormat;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class launches the camera view, allows the user to take a picture, closes the camera view,
|
* This class launches the camera view, allows the user to take a picture, closes the camera view,
|
||||||
@ -119,14 +120,14 @@ public class CameraLauncher extends Plugin {
|
|||||||
|
|
||||||
// Specify file so that large image is captured and returned
|
// Specify file so that large image is captured and returned
|
||||||
// TODO: What if there isn't any external storage?
|
// TODO: What if there isn't any external storage?
|
||||||
File photo = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
|
File photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.jpg");
|
||||||
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
||||||
this.imageUri = Uri.fromFile(photo);
|
this.imageUri = Uri.fromFile(photo);
|
||||||
|
|
||||||
this.ctx.startActivityForResult((Plugin) this, intent, (CAMERA+1)*16 + returnType+1);
|
this.ctx.startActivityForResult((Plugin) this, intent, (CAMERA+1)*16 + returnType+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get image from photo library.
|
* Get image from photo library.
|
||||||
*
|
*
|
||||||
* @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
* @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
||||||
@ -161,7 +162,6 @@ public class CameraLauncher extends Plugin {
|
|||||||
|
|
||||||
// If CAMERA
|
// If CAMERA
|
||||||
if (srcType == CAMERA) {
|
if (srcType == CAMERA) {
|
||||||
|
|
||||||
// If image available
|
// If image available
|
||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
try {
|
try {
|
||||||
|
@ -168,7 +168,7 @@ public class Capture extends Plugin {
|
|||||||
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
|
||||||
// Specify file so that large image is captured and returned
|
// Specify file so that large image is captured and returned
|
||||||
File photo = new File(Environment.getExternalStorageDirectory(), "Capture.jpg");
|
File photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Capture.jpg");
|
||||||
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
||||||
this.imageUri = Uri.fromFile(photo);
|
this.imageUri = Uri.fromFile(photo);
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ package com.phonegap;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.StatFs;
|
import android.os.StatFs;
|
||||||
|
|
||||||
@ -111,4 +112,31 @@ public class DirectoryManager {
|
|||||||
}
|
}
|
||||||
return newPath;
|
return newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if we can use the SD Card to store the temporary file. If not then use
|
||||||
|
* the internal cache directory.
|
||||||
|
*
|
||||||
|
* @return the absolute path of where to store the file
|
||||||
|
*/
|
||||||
|
protected static String getTempDirectoryPath(Context ctx) {
|
||||||
|
File cache = null;
|
||||||
|
|
||||||
|
// SD Card Mounted
|
||||||
|
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||||
|
cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
|
||||||
|
"/Android/data/" + ctx.getPackageName() + "/cache/");
|
||||||
|
}
|
||||||
|
// Use internal storage
|
||||||
|
else {
|
||||||
|
cache = ctx.getCacheDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the cache directory if it doesn't exist
|
||||||
|
if (!cache.exists()) {
|
||||||
|
cache.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache.getAbsolutePath();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user