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?
Related
When user press on button open sd card and can select any document in like gallery with Android SDK.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, setImageUri());
startActivityForResult(intent, IMAGE_CAPTURE);
Use Intent.ACTION_GET_CONTENT. On modern systems you can use Intent.ACTION_OPEN_DOCUMENT too.
I have created a pdf file in my application and successfully stored that in sdCard, now i want to store the pdf not in my sdcard but in Internal storage as shown here but when i open an intent for pdf readers as:
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
Log.v("Path",file.getAbsolutePath()); // Path data/data/com.cloudchowk.his.patient/files/LIPID PROFILE1300000403.pdf
i.setDataAndType(uri, "application/pdf");
startActivity(i);
The PDF reader shows an error The document path is not valid.
I have tried this on two devices one was rooted and one was not, but it was not working on any of them. What should i do ? any ideas?
Get the path and create URI
File internalFile = getFileStreamPath("pdf path");
Uri file = Uri.fromFile(internalFile);
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(file, "application/pdf");
startActivity(i);
To make a file from internal storage available to other apps the cleanest approach is to use a content provider.
Luckily, Android comes with FileProvider – an implementation that might just serve your needs.
You don't need to implement code, you just need to specifiy the provider in your manifest.
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.
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'm taking photos via Intent in my app, photos are saved into my specified folder on SD, but also they are saved into DCIM default camera folder. I do NOT want them twice. How can I disable saving of captured photos into this defalut camera directory?
Thank you in advance.
Here is what I'm using
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);