how to upload image captured from camera in an android app - android

in my app i have placed a button called Add Photo, when the user clicks the button a pop up menu appears with 2 option camera and library. When i select library i am able to move to the photo album of the device. Following is the code which i am using to go to the mobile library
public void library()
{
Intent myIntent = new Intent(Intent.ACTION_PICK);
myIntent.setType("image/*");
startActivityForResult(myIntent, 1);
}
whatever image i click there i want it to be uploaded in an url,
in the same way the image which i capture through the camera also want to be uploaded in an url.
how to do this is there any API or example code pls help me

This SO answer explains how to get the true path of the image in your onActivityResult
How to pick an image from gallery (SD Card) for my app?
Then look for an example on how to upload a file using http, any Java example ought to work, for instance:
http://www.jguru.com/faq/view.jsp?EID=62798

Related

Android - how to open image in gallery with delete option

I use following code to open an image in the gallery:
public void onItemClicked(PictureItem item){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri imageUri = FileProvider.getUriForFile(getApplicationContext(), "myapp.fileprovider", new File(item.uri.getPath()));
intent.setDataAndType(imageUri, "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
This shows my photo in the gallery, but in a 'read-only' mode. I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Which action do I have to use for that? I do not want to use pick, just normal view with the option to delete. I tried ACTION_EDIT but it's not supported (and not quite the right choice neither ...).
I use following code to open an image in the gallery
First, there are hundreds, if not thousands, of "gallery" apps available for Android.
Second, your code simply asks to view an image (with a broken Intent due to your wildcard MIME type). There is no requirement for the app that responds to be a "gallery" app.
I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Then implement that yourself, in your own app, and get rid of the ACTION_VIEW Intent.
Which action do I have to use for that?
There is no Intent action that says "please display this image, but only if you are a gallery app, and, oh, by the way, you must offer a delete option", which appears to be what you want.

How to draw on a photo IMMEDIATELY after taking it, THEN save to storage

I have searched around and found a few different solutions to this problem but none of them are really what I am looking for.
I am developing an app that lets the user take an image by opening the camera via a MediaStore.ACTION_IMAGE_CAPTURE Intent as so...
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
And then saves the image with
File photo = new File(Environment.getExternalStorageDirectory(), titleOfPhoto + ".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
I even get the thumbnail back and display it for the user in the onActivityResult() Override.
As the title suggests, what I would like to do is allow the user to draw on the captured image immediately after taking it. But I have no control over what happens between opening the camera and returning to my app with the captured image already saved. Apps like SnapChat and WhatsApp are doing exactly this and so much more, so I know it is possible, but Android does not appear to have this capability built in.
To be clear: The sequence of events needs to be
1) Open the camera
2) Take a picture
3) Draw on the picture
4) Press 'Ok'/'Done' or something
5) Save the edited photo
6) Return thumbnail
Is there anyway to add an event listener to the camera, or open the camera in a different manner that gives more control? Any help is appreciated! Thanks!
In order to do this, you will have to use the Camera Framwork API.
The basic of this is to render the camera output on a Surface View in your app. Then when the user takes a picture, capture the state of the surface view. From there you can allow your users to draw on the picture. When they are finished, THEN save the picture and display its thumbnail.

After intent to show image not all functions appear

I'm going to develop a simple app to list .jpg files and after a click call an Intent.ACTION_VIEW, below the code:
File imageFile = new File(filename);
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(imageFile), "image/jpeg");
startActivity(i);
The intent works properly, in fact in app I receive the message to select an app to show the selected image. But I noticed that after the choice, for example with Google Photos, not all function are enabled. For example the share function is not visible, has someone already noticed this behavior?
Some other details; if I choose Google Photos I only have the "Info" and "Guide and Feedback" options. If I choose gallery app (I have a Samsung Ace 3) I have only "Info" and "Set as wallpaper" options.
Note: if I open the same image directly from Google Photos all functions are enabled...
The ACTION_VIEW intent calls another application to view the content that you present, in your case a JPEG image. If there is more than on application that can handle that Intent, Android lets the user choose an app to display the image. Once the application receives the Intent, it is up to that application to display the content how it sees fit.
Basically, you have no control over what functions are available with Intent.ACTION_VIEW. If you want more control, you can create your own Activity in which you can view the image and provide whatever functions you would like.

Opening image in Gallery app programatically shows low resolution

I download and save an image on button click in my app. This works fine. If I view this image via the Gallery app (or any other way) it looks fine.
However, if I try to open the image with:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(imageFile), "image/*");
startActivity(intent);
It prompts me what app I want to open the file with (Gallery or Photos). If I select Gallery, the image opens but is very low resolution. As the photo contains a lot of text, it makes it so you can't zoom in and read. If I select "Photos", it looks fine.
Is there anything I can do to make it work fine in Gallery?
So I was saving the image with no extension. As it was opening in Gallery I figured it knew it was an image, but as soon as I added ".jpeg" to the file name, it showed in correct resolution. Strange bug, figured I'd update just in case someone else was hoping to find an answer here at some point.

Android - New intent with captured Image

I am developing an android app. When I capture an image using the code
Intent intent = new Intent(MediaStore.ActionImageCapture)
it will be stored in my sdcard as well as it will be displayed in the ImageView. Next, on button ‘Crop Picture’ click event, it should open the captured image as a new intent with the crop feature.
I've code to open the Gallery and select the captured image with the crop feature, but I don’t want the Gallery to get opened, instead I want the captured image in new intent with crop features.
Could anyone please assist?
In this case What you should do is, when it goes to next activity, save the image in local device, and put the image location as a intent value. Then when the new activity start, onCreate method, get the image location from intent values and load the image from the saved location. then delete the saved image.
If you can wait for few hours, I can put the code here.Feel free to ask anything until you get what you want.
Cheers!!

Categories

Resources