I have a weird problem!
My application calls the phone's camera to take a picture.
The photo is taken and stored in the ad hoc directory successfully
However, when I open the photo is not displayed (black screen)
and when I send the photo by email I can open it in my pc.
Here is the code :
String imageName = txtNomPhoto.getText().toString()+JPEG_FILE_SUFFIX;
File dossier = new File(Environment.getExternalStorageDirectory(),"/DossierPhotos");
if (!dossier.exists()){
if (dossier.mkdir()){
}
}
File mFichier = new File(dossier.getAbsolutePath(),imageName);
Uri fileUri = Uri.fromFile(mFichier);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, PHOTO_RESULT);
Thank you for your quick help.
Related
I'm using this code to open camera intent :
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePicture.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
startActivityForResult(takePicture, 0);
And it works fine but only on Samsung devices (8\9) with android 8
after I take a picture the preview is all blurry ,
anyone got that weird behavior ?
( I also tried without the putExtra line )
Here are the screenshots :
]3
you have to give a photo path Uri as an extra in the camera intent as:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), mUserID + ".jpg");
Uri photoPath = getUriForFile(mContext, BuildConfig.APPLICATION_ID, file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoPath); //--> here
startActivityForResult(Intent.createChooser(intent, "Complete action using"), REQUEST_CODE_CAMERA);
then, you can get the captured image in that Uri itself in onActivityResult
I am having a very difficult time with the camera intent and trying to get data about the photo that was just taken
I launch the camera like this
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File output = new File(dir, "IMG_" + timeStamp + ".jpg");
photoUri = Uri.fromFile(output);
startActivityForResult(camera, CAMERA_REQUEST);
in my onActivityResult the intent is null so I cannot use anything there to get the Uri but doing this.
Bitmap photo = MediaStore.Images.Media.getBitmap(getContentResolver(),photoUri);
gets the photo just fine. What I want to do is get information about the photo Latitude,Longitude,time taken etc so I tried this
MediaStore.Images.Media.query(getContentResolver(),photoUri,null,null,null,null);
but the cursor is always returned as null so it obviously cannot find the uri. It seems that the image is not getting out into the MediaStore provider. How can I get the data from the photo just taken?
I got this working with Images like:
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("image/*");
image = new File(projectPathFull,"testapp_"+imageCounter+".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
startActivityForResult(intent, REQUEST_PICK_IMAGE);
This creates the picked image in my folder testapp
But it doesnt work with Audiofiles somehow.
This is my code:
Intent toAudioSelect = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
audio = new File(projectPathFull,"testapp_"+imageCounter+".mp3");
toAudioSelect.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(audio));
startActivityForResult(toAudioSelect, REQUEST_PICK_AUDIO);
Any Ideas?
I am using this code to take the picture from the camera
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
File storagePath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/Camera/");
if(!storagePath.isDirectory()){
storagePath.mkdirs();
}
File myImage = new File(storagePath,
Long.toString(System.currentTimeMillis()) + ".jpg");
Uri fromURI=Uri.fromFile(myImage);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fromURI);
startActivityForResult(intent,PulseConstants.CAMERA_REQUEST_CODE);
The image is stored correctly with the given file name in "My Files" folder of the phone...But when I open Gallery of the phone, this image does not appear ??
Please let me know if I am doing anything wrong??
TIA,
VijayRaj
This may have to do with the fact that the Android media scanner is not constantly indexing files on the phone. In the past I have called the following function immediately after saving an image to notify the MediaScanner:
private void scanMedia(File file) {
Uri uri = Uri.fromFile(file);
Intent scanFileIntent = new Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
sendBroadcast(scanFileIntent);
}
Hope this works!
I am launching the image capture intent to take a picture, adding a uri so the picture is tiny. My problem is I want to set the output jpeg-quality before I start the activity.
ContentValues vals = new ContentValues();
vals.put(Media.DISPLAY_NAME, "test title");
vals.put(Media.MIME_TYPE, "image/jpeg");
Uri imageFileUri = context.getContentResolver()
.insert(Media.EXTERNAL_CONTENT_URI, vals);
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
context.startActivityForResult(i, CameraImportActivity.CAMERA_REQUEST);
I suppose I could downsample after the picture is taken, but if I can request the activity do it for me I would like to do so.
As bonus questions, how do I change the album they get saved to in the gallery, and how do I prevent the camera activity from saving a copy in the default location (on my phone it is "photos")