Android Take Photo and Save to Variable - java

I would like to allow the user to take a photo, and when finished, have it passed directly into a variable (Bitmap preferably) instead of saved to memory. I've tried using the default android camera intent but cannot seem to stop it from saving to memory and showing up in the gallery.
Any suggestions?
What I have so far is this:
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, 1);
}
But this saves the picture in the gallery. I would like to get the image without saving it in the gallery.

Here's a nice example given at official android developer site: http://developer.android.com/training/camera/photobasics.html
Hope this would be helpful.

Related

Android - where are videos taken from intent stored?

Let's say I have a method inside my activity that looks like this:
private void dispatchTakeVideoIntent() {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
}
Then if everything works out fine, I access the taken video by its URI:
public void onActivityResult(int requestCode, int resultCode, #Nullable Intent intent) {
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == Activity.RESULT_OK) {
Uri videoUri = intent.getData();
// process video
}
}
Where does the video actually reside at this point? Is it temporarily stored in memory or does it get saved to permanent storage?
If I want my app to reliably access that video at some later point, what's the best way to go about this? Do I have to copy the video to my app's storage folder(s)?
Where does the video actually reside at this point?
It will reside wherever the user's camera app elects to put it. There are hundreds of different camera apps, both pre-installed by manufacturers and user-installed from the Play Store or elsewhere.
Is it temporarily stored in memory or does it get saved to permanent storage?
That is up to the camera app.
If I want my app to reliably access that video at some later point, what's the best way to go about this?
You can try passing a content Uri value via EXTRA_OUTPUT as an extra on your Intent. You can use FileProvider to get that Uri, pointing to some file in a location that you control (e.g., getFilesDir() on Context). Most camera apps should honor this extra, but not all will.
Or, you could copy the video, as you suggest.
Or, you could use a camera library (e.g., FotoApparat, CameraKit-Android) and record the video within your own app.

Android Jelly bean camera return null URI

I'm trying to use the camera to take pictures in my app, and then crop the taken images.
Everything is working for the recent versions for Android, but not for Android Kitkat 4.4.2.
the Camera returns a null URI.
get the URI onActivityReslult :
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_CODE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
picUri = data.getData();
Intent i = new Intent(PublierActivity.this, CropActivity.class);
i.putExtra("Uri", picUri);
startActivityForResult(i, CROP_CODE);
}
Here is how I call the camera intent :
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, CAMERA_CODE);
}
is there any way to make an exception for oldest versions for android to resolve this problem ?
From your code, it would appear that you are trying to use ACTION_IMAGE_CAPTURE. In that case, there should never be a Uri — data.getData() should always be returning null. If a camera app happens to return a Uri, that may be the image, but since ACTION_IMAGE_CAPTURE is not documented to return a Uri, you have no way of knowing what that Uri is for.
If you are using EXTRA_OUTPUT on the ACTION_IMAGE_CAPTURE Intent, you know where the image should be stored, because you told the camera app where to store it. Note that some camera apps are buggy and fail to honor EXTRA_OUTPUT, putting the image wherever they want.
If you are not using EXTRA_OUTPUT, then you will get a thumbnail back in the "data" extra.
Also, please bear in mind that this has nothing to do with Android OS version, and everything to do with the camera app that the user chooses to use. There are thousands of Android device models. These ship with dozens, if not hundreds, of different camera apps pre-installed. The user might also elect to install a third-party camera app. Any of those could be handling your request.

Front facing camera takes upside down pictures

So, I am developing a small game for my final school project, and I am having this problem, whenever I take a picture with the front facing camera, it saves it upside down, when I use the good old back camera however, it's all fine and it takes the photo properly. Here's the code that I'm using to take the picture:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageFile = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "goQuiz/profilePic.jpg"
);
Uri tempuri = Uri.fromFile(imageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, tempuri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
I used this video to help me get the code done: Video.
Any help will be greatly apreciated, thanks.

Android java. Saved image doesn't show in gallery immediately

I am saving a bitmap . It saves to some root. But doesn't show in gallery. it show in gallery after restarting the device. I tried to send broadcast but it doesn't work for android 4.4.How can I do it to work for api 9-19
The built-in Gallery scans the phones memory when it thinks it's necessary. You can't force it to. Normaly restarting the gallery should help.
Edit:
I might have found an intent to refresh the gallery:
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
getApplicationContext().sendBroadcast(mediaScanIntent);
(f is the file wich has been added and should be scanned.) I haven't tried this yet, but it seems legit.

EXTRA_OUTPUT ignored on Eris, causes data to return null on G1

So I'm trying to launch the Camera activity using the following code:
//In public void captureImage()
...
Intent cameraIntent = new Intent(MediaStore.ACTION_CAPTURE_IMAGE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(new File("/sdcard/image.jpg")));
startActivityForResult(cameraIntent, REQUEST_CAMERA);
And then to handle the result:
//In onActivityResult()
...
case REQUEST_CAMERA:
Intent intent = new Intent (CurrentScreen.this, NextScreen.this);
intent.putExtra(data);
startActivity(intent);
CurrentScreen.this.finish();
...
Where I use intent.putExtra(data) to attach the small bitmap to the intent, and use it as a thumbnail in the next activity, and the full sized file is supposedly saved as /sdcard/image.jpg.
This is the expected behavior (according to the documentation), to have a small bitmap for a thumbnail, and a large file saved. However when testing this on a G1 and an Eris, I have been seeing some strange behavior.
On the G1:
Although the resultCode shows RESULT_OK, the intent data that is returned to the result handler is null.
Also EXTRA_OUTPUT seems to be completely ignored, I have no idea where it is saving the image.
On the Eris:
The intent data comes back OK
EXTRA_OUTPUT is also ignored, but it is saving the images to the regular media store at /sdcard/dcim/100media
So my question is this: is there any way to get consistent behavior for what I am trying to do using the standard camera activity? I could write up a custom activity to try and get it to work the way I want, but I'd prefer to avoid that route.
I do not have answers to your question as I am new to the Java/Android development world. But I am attempting something similar to what you are doing, except I want to simply take the picture then attach it to an Email message.
I implemented part of your example and was able to verify that the camera created the file I specified and that if I use the same file name for the next picture that it overwrites the previous file which is what I would expect.
But what I was really going to say is perhaps you will have to test if the pat "/sdcard/..." actually exists or not. Also you could possibly simplify your process by passing the path to the next activity.
Good Luck,
Jamie Irwin

Categories