I am receive an URI from my Activity. I want to be able to save a picture from my Custom Camera into that specific location, I don't know how to achieve that. Can I get some help?
I see how to save an image from the Google developer website but they create a folder, name the picture with date and etc. I have an URI which contains all the information. All I need to do is to save a picture in that URI.
Initially, I am trying to achieve manually what the camera intent does when you add this extra:
intent.putExtra(MediaStore.EXTRA_OUTPUT, URI_GOES_HERE);
Here is the code in the current Activity where the URI is passed to my Custom Camera as an Extra:
String filename = System.currentTimeMillis() + ".jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, filename);
preDefinedCameraUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
Log.d("Predefined URI:","" + preDefinedCameraUri);
intent.putExtra(MediaStore.EXTRA_OUTPUT, preDefinedCameraUri);
How do I save the picture in that extra?
Related
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 am working on Wallpaper app, in which user can set wallpaper and share that wallpaper also via bluetooth, and other apps also.
I have used following to identify user selected wallpaper.
ImageView imagePreview = (ImageView) findViewById(R.id.iv_preview);
imagePreview.setTag("a1");
And used getTag() in my another function to use that selected wallpaper.
To share the user selected image i have used following code
String mDrawableName = (String) imagePreview.getTag();
Uri imageUri = Uri.parse("android.resource://com.mypackage.wallpaperapp/drawable/"+mDrawableName);
Log.d("here i got", imageUri.toString()); // here i got android.resource://com.mypackage.wallpaperapp/drawable/a3
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share From"));
But i am getting the the error in device that " file unknown file cannot send",
Where am i wrong here?
I found in some stuff that i have to firstly save my image resource into storage and after that i can send my image.
But i dont know how can i save my image resource file into storage and send it to via different apps.
Please Help.
Maybe this answer can help you:
https://stackoverflow.com/a/19618432/3743093
In short: you can't pass an URI created with
Uri uri = Uri.parse(String);
to shareIntent, beacuse it lacks info like TITLE and MIME_TYPE.
That's because file type is unknown (missing) and throws this error.
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Uri.parse(filename),
values);
Hope this helps.
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 trying to record a video in Android using the MediaStore.ACTION_VIDEO_CAPTURE intent. I can record the video in the default library album, but I cannot store anywhere else. I have tried to use the intent parameter EXTRA_MEDIA_ALBUM:
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_MEDIA_ALBUM, "My app videos");
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
I have also tried to insert the video row in the MediaStore before the video itself.
ContentValues videoValues = new ContentValues();
videoValues.put(MediaStore.Video.Media.TITLE, "My app video at" + System.currentTimeMillis());
videoValues.put(MediaStore.Video.Media.ALBUM, "My app videos");
Uri videoUri= getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoValues);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, 0);
And I have also tried to modify the metadata once the video is inserted, to see if it is in a different album once I open the gallery application.
protected void onActivityResult(final int requestCode, final int resultCode, final Intent dataIntent) {
...
Uri contentUri = dataIntent.getData();
ContentValues values = new ContentValues();
values.put(MediaStore.Video.Media.ALBUM, "My app videos");
int result = getContentResolver().update(contentUri, values, null, null);
'result' is 1, so the row value is actually changed, but it is not in "My app videos" album once I open it.
I have also tried different solutions explained in the Android documentation but with any Uri an IllegalArgumentException (Unknown URL file). I miss a handy method like MediaStore.Images.Media.insertImage
How have you dealt with this problem?
I have a similar problem, although my code is on two parts, one that deals Photos and the other that deals Videos, the same process and scenario gives two different results, the following thread explains more!
http://www.androidquestions.org/threads/618-Intent-doesn-t-keep-video-extras-after-capturing-the-video!?p=1761#post1761
I would be thankful if this issue has any solutions!
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")