mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-01-31 12:42:50 +08:00
CB-11625: Managed to get Content Providers to work with a weird mix of Content Providers and non-Content Providers
This commit is contained in:
parent
b62fdf50f7
commit
00e0a7dc46
@ -33,12 +33,13 @@ import java.util.Date;
|
|||||||
import org.apache.cordova.CallbackContext;
|
import org.apache.cordova.CallbackContext;
|
||||||
import org.apache.cordova.CordovaPlugin;
|
import org.apache.cordova.CordovaPlugin;
|
||||||
import org.apache.cordova.CordovaResourceApi;
|
import org.apache.cordova.CordovaResourceApi;
|
||||||
|
import org.apache.cordova.CoreAndroid;
|
||||||
import org.apache.cordova.LOG;
|
import org.apache.cordova.LOG;
|
||||||
import org.apache.cordova.PermissionHelper;
|
import org.apache.cordova.PermissionHelper;
|
||||||
import org.apache.cordova.PluginResult;
|
import org.apache.cordova.PluginResult;
|
||||||
import org.apache.mobilespec.BuildConfig;
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
import org.apache.cordova.Api24Camera.BuildConfig;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -120,6 +121,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
private MediaScannerConnection conn; // Used to update gallery app with newly-written files
|
private MediaScannerConnection conn; // Used to update gallery app with newly-written files
|
||||||
private Uri scanMe; // Uri of image to be added to content store
|
private Uri scanMe; // Uri of image to be added to content store
|
||||||
private Uri croppedUri;
|
private Uri croppedUri;
|
||||||
|
private String applicationId;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,6 +134,10 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
*/
|
*/
|
||||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||||
this.callbackContext = callbackContext;
|
this.callbackContext = callbackContext;
|
||||||
|
//Adding an API to CoreAndroid to get the BuildConfigValue
|
||||||
|
//This allows us to not make this a breaking change to embedding
|
||||||
|
this.applicationId = (String) CoreAndroid.getBuildConfigValue(cordova.getActivity(), "APPLICATION_ID");
|
||||||
|
|
||||||
|
|
||||||
if (action.equals("takePicture")) {
|
if (action.equals("takePicture")) {
|
||||||
this.srcType = CAMERA;
|
this.srcType = CAMERA;
|
||||||
@ -233,8 +239,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
* or to display URI in an img tag
|
* or to display URI in an img tag
|
||||||
* img.src=result;
|
* img.src=result;
|
||||||
*
|
*
|
||||||
* @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
|
||||||
* @param returnType Set the type of image to return.
|
* @param returnType Set the type of image to return.
|
||||||
|
* @param encodingType Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
||||||
*/
|
*/
|
||||||
public void callTakePicture(int returnType, int encodingType) {
|
public void callTakePicture(int returnType, int encodingType) {
|
||||||
boolean saveAlbumPermission = PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
boolean saveAlbumPermission = PermissionHelper.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||||
@ -285,7 +291,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
// Specify file so that large image is captured and returned
|
// Specify file so that large image is captured and returned
|
||||||
File photo = createCaptureFile(encodingType);
|
File photo = createCaptureFile(encodingType);
|
||||||
this.imageUri = FileProvider.getUriForFile(cordova.getActivity(),
|
this.imageUri = FileProvider.getUriForFile(cordova.getActivity(),
|
||||||
BuildConfig.APPLICATION_ID + ".provider",
|
applicationId + ".provider",
|
||||||
photo);
|
photo);
|
||||||
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, this.imageUri);
|
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, this.imageUri);
|
||||||
//We can write to this URI, this will hopefully allow us to write files to get to the next step
|
//We can write to this URI, this will hopefully allow us to write files to get to the next step
|
||||||
@ -346,7 +352,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
/**
|
/**
|
||||||
* 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 srcType The album to get image from.
|
* @param srcType The album to get image from.
|
||||||
* @param returnType Set the type of image to return.
|
* @param returnType Set the type of image to return.
|
||||||
* @param encodingType
|
* @param encodingType
|
||||||
@ -411,6 +416,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
// set crop properties
|
// set crop properties
|
||||||
cropIntent.putExtra("crop", "true");
|
cropIntent.putExtra("crop", "true");
|
||||||
|
|
||||||
|
|
||||||
// indicate output X and Y
|
// indicate output X and Y
|
||||||
if (targetWidth > 0) {
|
if (targetWidth > 0) {
|
||||||
cropIntent.putExtra("outputX", targetWidth);
|
cropIntent.putExtra("outputX", targetWidth);
|
||||||
@ -423,11 +429,12 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
cropIntent.putExtra("aspectY", 1);
|
cropIntent.putExtra("aspectY", 1);
|
||||||
}
|
}
|
||||||
// create new file handle to get full resolution crop
|
// create new file handle to get full resolution crop
|
||||||
croppedUri = FileProvider.getUriForFile(cordova.getActivity(),
|
croppedUri = Uri.fromFile(createCaptureFile(this.encodingType, System.currentTimeMillis() + ""));
|
||||||
BuildConfig.APPLICATION_ID + ".provider",
|
cropIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
createCaptureFile(this.encodingType, System.currentTimeMillis() + ""));
|
cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||||
cropIntent.putExtra("output", croppedUri);
|
cropIntent.putExtra("output", croppedUri);
|
||||||
|
|
||||||
|
|
||||||
// start the activity - we handle returning in onActivityResult
|
// start the activity - we handle returning in onActivityResult
|
||||||
|
|
||||||
if (this.cordova != null) {
|
if (this.cordova != null) {
|
||||||
@ -460,7 +467,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
ExifHelper exif = new ExifHelper();
|
ExifHelper exif = new ExifHelper();
|
||||||
|
|
||||||
String sourcePath = (this.allowEdit && this.croppedUri != null) ?
|
String sourcePath = (this.allowEdit && this.croppedUri != null) ?
|
||||||
getFileNameFromUri(this.croppedUri) :
|
FileHelper.stripFileProtocol(this.croppedUri.toString()) :
|
||||||
getFileNameFromUri(this.imageUri);
|
getFileNameFromUri(this.imageUri);
|
||||||
|
|
||||||
|
|
||||||
@ -487,7 +494,6 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
|
|
||||||
|
|
||||||
if (this.allowEdit && this.croppedUri != null) {
|
if (this.allowEdit && this.croppedUri != null) {
|
||||||
Uri croppedUri = Uri.fromFile(new File(getFileNameFromUri(this.croppedUri)));
|
|
||||||
writeUncompressedImage(croppedUri, galleryUri);
|
writeUncompressedImage(croppedUri, galleryUri);
|
||||||
} else {
|
} else {
|
||||||
Uri imageUri = Uri.fromFile(new File(getFileNameFromUri(this.imageUri)));
|
Uri imageUri = Uri.fromFile(new File(getFileNameFromUri(this.imageUri)));
|
||||||
@ -791,7 +797,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
try {
|
try {
|
||||||
if (this.allowEdit) {
|
if (this.allowEdit) {
|
||||||
Uri tmpFile = FileProvider.getUriForFile(cordova.getActivity(),
|
Uri tmpFile = FileProvider.getUriForFile(cordova.getActivity(),
|
||||||
BuildConfig.APPLICATION_ID + ".provider",
|
applicationId + ".provider",
|
||||||
createCaptureFile(this.encodingType));
|
createCaptureFile(this.encodingType));
|
||||||
performCrop(tmpFile, destType, intent);
|
performCrop(tmpFile, destType, intent);
|
||||||
} else {
|
} else {
|
||||||
@ -881,7 +887,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
* In the special case where the default width, height and quality are unchanged
|
* In the special case where the default width, height and quality are unchanged
|
||||||
* we just write the file out to disk saving the expensive Bitmap.compress function.
|
* we just write the file out to disk saving the expensive Bitmap.compress function.
|
||||||
*
|
*
|
||||||
* @param uri
|
* @param src
|
||||||
|
* @param dest
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user