Prevent Adobe CreativeSDK plugin from saving the edited file automatically - android

How to Prevent Adobe Creative SDK plugin from saving the edited file automatically in android?
When i try to edit the image, the file is automatically saved to device.

It's not possible to avoid saving the image, but you can set where it is saved using the AdobeImageIntent.Builder()'s .withOutput() method. Example:
Intent imageEditorIntent = new AdobeImageIntent.Builder(this)
.setData(uri) // input image source
.withOutput(Uri.parse("file://" + getFilesDir() + "/my-pic-name.jpg")) // output file destination
.build();
Whether you set the location using .withOutput() or not, you will get back the saved image's Uri in your onActivityResult() method:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
/*
`1` being an arbitrary int we used as a requestCode
when starting the `imageEditorIntent`
*/
case 1:
// Do things, for example:
Uri editedImageUri = data.getData();
mEditedImageView.setImageURI(editedImageUri);
break;
}
}
}
If you don't want to store the data long term, you might use that Uri to go back and delete the saved image when you are done with it.

Related

Take picture with camera in android 10

With all of the changes in android 10 that are related to scoped storage, how can we open the camera. I saw some tutorial that suggest using a file provider, but I don't really quite get it.
Can you provide a snippet of code to launch the camera intent, and receive the taken image ?
Edit :
In this article : https://medium.com/#arkapp/accessing-images-on-android-10-scoped-storage-bbe65160c3f4
He provided this code :
fun takePicture(context: Activity, imageName: String) {try {
val capturedImgFile = File(
context.getExternalFilesDir(Environment.DIRECTORY_PICTURES),
imageName)
captureImgUri = FileProvider.getUriForFile(
context,
context.applicationContext.packageName + ".my.package.name.provider",
capturedImgFile)val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE).also {
it.putExtra(MediaStore.EXTRA_OUTPUT, captureImgUri)
it.putExtra("return-data", true)
it.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
context.startActivityForResult(it, REQUEST_CODE_TAKE_PICTURE)
}
} catch (e: ActivityNotFoundException) {e.printStackTrace()}
}#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {return}
if (requestCode == REQUEST_CODE_TAKE_PICTURE) {
/*We cannot access the image directly so we again create a new File at different location and use it for futher processing.*/
Bitmap capturedBitmap = getBitmap(this, captureImgUri)
/*We are storing the above bitmap at different location where we can access it.*/ val capturedImgFile = File(
getExternalFilesDir(Environment.DIRECTORY_PICTURES),
getTimestamp() + "_capturedImg.jpg"); convertBitmaptoFile(capturedImgFile, capturedBitmap)/*We have to again create a new file where we will save the processed image.*/ val croppedImgFile = File(
getExternalFilesDir(Environment.DIRECTORY_PICTURES),
getTimestamp() + "_croppedImg.jpg"); startCrop(
this,
Uri.fromFile(capturedImgFile),
Uri.fromFile(croppedImgFile))}
super.onActivityResult(requestCode, resultCode, data)
}
I have two questions:
What does this line do :
it.putExtra("return-data", true)
in OnActivityResulty, why didn't he just use the uri directly, he first created a file and then parsed the file into an uri, what is this for ? how does it have to do android 10 scoped storage ?
What does this line do : it.putExtra("return-data", true)
Nothing, usually. It's possible that there are some camera apps that will do something when receiving this undocumented and (generally) unsupported Intent extra.
in OnActivityResulty, why didn't he just use the uri directly
He does, in earlier steps. By the end, he wants to use uCrop to allow the user to crop the image. Perhaps he wants to hold onto both the original and the cropped photo.

How to convert content:// to file after image capture android?

I am capturing image using camera in android using the following code snippet.
Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(Constants.ATTACH_IMAGE);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
imageIntent.putExtra("outputFormat",Bitmap.CompressFormat.JPEG.toString());startActivityForResult(imageIntent, Constants.ATTACH_IMAGE);
in onActivityResult, I want to convert the "content://" uri back to File, compress it and show a thumb nail.
How can I do it?
Edit :-
What I have tried:-
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("activity result","coming" + String.valueOf(requestCode)+ contentFileUri);
// View popupView = getActivity().getLayoutInflater().inflate(R.layout.popup_add_snag, null);
// LinearLayout attachLayout = (LinearLayout)popupView.findViewById(R.id.attachLayout);
// ImageView photoImageicon = (ImageView)popupView.findViewById(R.id.imageicon);
try{
// if (resultCode == Constants.RESULT_OK){
if(contentFileUri !=null) {
Log.d("fileuri", contentFileUri.toString());
String attachmentType = "IMAGE";
// mAdapter.attachmentType=attachmentType;
photoImageIcon.setVisibility(View.VISIBLE);
// attachLayout.setVisibility(View.INVISIBLE);
Toast.makeText(getActivity().getApplicationContext(), R.string.successfull_image, Toast.LENGTH_SHORT).show();
Log.d("fileuri", contentFileUri.toString());
InputStream inputStream = getContext().getContentResolver().openInputStream(contentFileUri);
contentFileUri looks like this:- "content://com.fa.ha.provider/external_files/F/7c7.jpeg"
But above results in "FileNotFound Exception, not a directory" at the last line.
Ideally, just hang onto the File that getOutputMediaFileUri() is creating. Hopefully, getOutputMediaFileUri() is setting up a FileProvider Uri for you, based off of a File, so if you hold onto the File, you do not need to worry about "converting" anything. See this sample app.
If getOutputMediaFileUri() is poorly written, perhaps you do not have a File. In that case, in onActivityResult(), you can pass the Uri to an image-loading library (Picasso, Glide, etc.) and have it populate an ImageView or simply load the Bitmap for you.

Android capture and use image not working

I've written code in Android to capture an image and then use that image as follows:
private static Intent i;
final static int cons = 0;
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
public void takePicture()
{
i= new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //Open camera
startActivityForResult(i, cons);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Log.d("Testing if condition", "Test"); //This code does not execute
Bundle ext = data.getExtras();
Log.d("Upload image", ext.toString());
sendForUpload(data); // function to upload file to server
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
}
}
}
This code lets me take a photo and it saves to the SD card. However, I'm not sure if the file is sent to the sendForUpload function where I've handled getting the path and uploading the file. In fact nothing inside the if (resultCode == RESULT_OK) block works. How do I use the image captured from this activity?
Well, you have a few problems.
First, you are calling startActivityForResult(i, cons);. cons is 0. You are trying to compare 0 with CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE. Since CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE is 100, that will not work.
Second, you are calling data.getExtras().toString() (split over two Java statements). I would expect this to return a value like android.os.Bundle#34334143. If that is what you want to upload, fine. I am guessing that you want to upload the image. Since you did not include EXTRA_OUTPUT in your ACTION_IMAGE_CAPTURE Intent, you get a Bitmap of the thumbnail image taken by the camera via data.getParcelableExtra("data").
Third, you are making inappropriate assumptions:
This code lets me take a photo and it saves to the SD card.
There is no requirement for the camera app to save the image anywhere, let alone to removable storage. In fact, I would argue that this is a bug in your camera app. That is not surprising, as ACTION_IMAGE_CAPTURE implementations have bugs.
where I've handled getting the path and uploading the file
There is no path. You did not include EXTRA_OUTPUT in your ACTION_IMAGE_CAPTURE Intent, and so all you get back is the thumbnail Bitmap.
I'm using this to put the image in a ImageView:
Uri uri = data.getData();
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
You can use bitmap or uri objects for upload or show your picture..
Hope it helps you.

How to change the directory of SquareCamera library?

I am using SquareCamera library (https://github.com/boxme/SquareCamera) for taking square picture.The problem I am facing is that SquareCamera is creating its own folder where taken pics are getting stored. I want these pics to store in my own folder. I don't know how to achieve that. I am very new to android. Below is the code where instead of default camera I am calling its own class.
public void onLaunchCamera(View view) {
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(this,CameraActivity.class);
// Start the image capture intent to take photo
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
And this is the onActivityResult method
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Uri takenPhotoUri = data.getData();
Bitmap takenImage = BitmapFactory.decodeFile(takenPhotoUri.getPath());
imageView.setImageBitmap(takenImage);
I thought about saving this bitmap into my own folder but I couldn't think how to delete the created directory of SquareCamera.
So I found the solution. I added the library as a module in my app. Referring (https://www.youtube.com/watch?v=1MyBO9z7ojk). And there I changed the source code a little bit and now it's working perfect.
I'm a bit long in the tooth at Android and am not 100% with the new Uri methods of file access enforced since KitKat. For conventional file access you can get a private writeable file using.
private static final File OUTPUT_DIR = Environment.getExternalStorageDirectory();
FileOutputStream fos;
void yourMethodBeginsHere() {
String outputPath = new File(OUTPUT_DIR, "test.png").toString();
try {
fos = new FileOutputStream(outputPath, false);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//Work with file
}
If you need a truly external file path please refer to the excellent answer already existing at https://stackoverflow.com/a/26765884/5353361 which deals fully with the new Uri based system of permissions and the integrated file explorer.

Getting images from system Gallery. Why is not working?

I made a program where user show which picture he want to load in this app. When user want to load picture, he can choose what kind of file explorer he want to use:
Everything works, but if I choose "Gallery" and mark my image, it doesn't work. It happens only when i choose "Gallery".
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
String path = data.getData().getPath();
try {
loadedimage = BitmapFactory.decodeFile(sciezka_z_obrazem);
}
catch (Exception e) {
}
} [...]
After picking image from Gallery, loadedimage is null.
When I use Dropbox or "My Files" everything is OK.
I guess you should use
Uri mUri = data.getData();
In case of Gallery the file returned is of the form content:// rather than file://
So you should use the uri rather than doing getPath on uri
Edit:
Use uri to decode like below
InputStream is = getContentResolver().openInputStream(uri);
loadedimage = BitmapFactory.decodeStream(is)
You should try this.
File filePath= new File(path);
and then use
Uri.fromFile(filePath)
this would set the content wchich could be openend.

Categories

Resources