in my app, using Gingerbread, this piece of code works:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA);
But in ICS (I tried on different ROMs), using
Uri selectedImageUri = data.getData();
returns null.
How can I make the first code work?
Thanks in advance
.
PS: I found this solution:
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(dir, "avatar.jpeg")));
But if a device haven't a storage expansion? Plus I dont need to save the image.
Related
In my app, I am calling camera that should capture picture and store it on given path:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
public static String pic_path =Environment.getExternalStorageDirectory().toString()+name;
File file = new File(pic_path);
Uri outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, REQUEST_CAMERA);
It works fine on devices that have SD card or any kind of External Storage. But it does not work on others (it crashes). So, what is alternative? How would I make this code work for devices without SD card/External Storage?
I am currently using a photo gallery I built through GridLayout but this seems to use a lot of memory (OOME coming up) when dealing with a lot of Bitmaps. Therefore, I am trying to use the Intent.ACTION_GET_CONTENT to open photos on the device and select photos through there.
The camera function works correctly as it takes the photo, returns to the onActivityResult function, and updates it to my Gridlayout photo gallery.
I am currently on a Nexus 7 running Android 4.4 (KitKat)
[PROBLEMS]
When I try to view photos through Intent.ACTION_GET_CONTENT, none of the new photos I just took through the application are there.
Running Intent.ACTION_GET_CONTENT to filter results from a specific directory and file type doesn't seem to work.
[Code information]
MainForm is a (class)
photoPath = new File(directory, photoName)
directory is a (File) set to my current working directory
photoName is a (String)
CAMERA_CODE is an (int)
[MY CODE]
Here is my code for launching the camera:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cUri = Uri.fromFile(photoPath);
intent.putExtra(MediaStore.EXTRA_OUTPUT, cUri);
startActivityForResult(intent, CAMERA_CODE); // launch camera
[What I tried + Errors for Updating Photo Gallery library]
MediaScannerConnection
I tried to use this to update the photolist and then launch the intent, but it did not work (I may be using this incorrectly, but it was suggested in this post)
MediaScannerConnection.scanFile(MainForm.this, new String[] { directory.getAbsolutePath() },null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setData(uri);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 12345);
}
});
getContentResolver()
I read in this question to try using this method, but it doesn't seem to work either
MainForm.this.getContentResolver().notifyChange(MediaStore.Images.Media.INTERNAL_CONTENT_URI, null);
sendBroadcast
In this question and here to re-index photos on the device, the answer suggested using sendBroadcast
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(directory)));
but I was greeted with this error
E/AndroidRuntime(30177): java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=30177, uid=10122
What does this error mean?
[What I tried + Errors for ACTION_GET_CONTENT intent]
No matter what I put under intent.setData, opening the intent doesn't seem to open that folder, but instead it opens the android browser under the tab "Recent"
I followed this question
ANY TIPS OR SUGGESTIONS WOULD BE GREATLY APPRECIATED! If there are any other codes or log results I should post, please comment below!
I'm trying to follow this tutorial: http://mobile.tutsplus.com/tutorials/android/capture-and-crop-an-image-with-the-device-camera/
But, after taking the photo, when the picture is going to be cropped, appears, "loading image..." forever.
I've tried to Toast the "picUri = data.getData();" and it returned null. I've read that in some devices we need to specify filename for picture to be taken, so I tried, but no good results.
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, "file:///tmp/android.jpg");
startActivityForResult(captureIntent, CAMERA_CAPTURE);
I'm testing it in a Galaxy Nexus and a Galaxy 5.
Someone have any idea?
Thank you.
I think the file path you are providing to the EXTRA_OUTPUT is wrong. Instead try using something like this:
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp/android.jpg";
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, storagePath);
startActivityForResult(captureIntent, CAMERA_CAPTURE);
We are making an application and in it, we want the ability to save an image. It works great and saves the image automagically on my friends phone which is a samsung galaxy II. But on my Galaxy Nexus it just returns the bitmap data.
The problem is that we are using a function to get the last image path and since Galaxy Nexus won't save the file it just takes the last photo taken with the normal camera application.
This is our code before on result:
private void takePhoto() {
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
}
So what I want is the know-how to save the image on the sdcard so we can use it later.
The following code should tell the camera to save the image to /sdcard/file.jpg:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri mImageCaptureUri = Uri.fromFile(new File(Environment
.getExternalStorageDirectory(), "file.jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
mImageCaptureUri);
intent.putExtra("return-data", true);
startActivityForResult(intent, 0);
i've been trying to create a camera-related app. i know that i could create it programmatically from top, but i would prefer using the one that the phone supports.
what i mean is, rather then creating the camera from 0, i would/could call the camera activity. after all, it provides all the system and gui that i needed.
however, the problem is i wanted the result/image took to be saved in a folder that i created before, rather then saving it in the default camera folder. and also renaming the image took that instant from the default 'image' to names that i preferred.
how do i control that ?
Try this. Here am saving picture to sdcard and also changing its name while saving.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
"pic"+ String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
If you look at the Camera applicaton source code, it allows for startActivityForResult(..) that can return the image back to you. This is ideally what you'd like to do.
As a Little hint:
MediaStore
Use below method to take picture, SD_CARD_TEMP_DIR is the path and the image name you want it to store. Hope it help
private void takePicture(){
SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator + "farmerImage"+CassavaPref.getInstance(this).getImageSuffix()+".jpg";
file =new File(SD_CARD_TEMP_DIR);
Intent takePictureFromCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(takePictureFromCameraIntent, 1111);
}