How to create camera button that stores images to gallery? - android

How would I correctly get a buttons intent to take a picture and store that image in the phones gallery? So far i have a button which is in a case structure that says :
else if (v.getId() == R.id.button5)//camera
{
Intent c = new Intent( MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(c,1);
}
what should my onActivityResult look like since i am just storing that image to the gallery?
would i have to use something as bundle extras = data.getExtras();?

This answer may be your problems solution. But data.getExtras() returns null in some cases and unfortunately I have not detected all of these cases yet. For example data.getExtras() worked fine on android 2.3 HTC Evo 3D but on android 2.3 Samsung Galaxy SII, it returned null. Hope this helps.

First, you have to call your startActivityForResult() method like the following:
Uri imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(i, CAMERA_RESULT);
And in the implementation of startActivityForResult() method you have to write the following:
// Save the name and description of an image in a ContentValues map.
ContentValues contentValues = new ContentValues(3);
contentValues.put(Media.DISPLAY_NAME, "This is a test title");
contentValues.put(Media.DESCRIPTION, "This is a test description");
contentValues.put(Media.MIME_TYPE, "image/jpeg");
// Add a new record without the bitmap, but with some values set.
// insert() returns the URI of the new record.
Uri imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,contentValues);

Related

Getting image orientation picking multiple images from gallery

I'm facing a problem that I cannot solve. I would be grateful if you could help me.
I would like to make an app that picks one or more images from the gallery, elaborates them and saves them into a folder.
The problem I have is to rotate the images correctly.
When I pick one image (see the code below), the app rotates the image correctly.
If I pick more images simultaneously (see the code below) I cannot rotate them because the value of "rotation" (see the code below) is always 0 (zero).
To pick one image from the gallery, I use the following code:
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, RESULT_LOAD_IMG);
In "OnActivityResult" I get the URI path as following:
Uri imageUri = data.getData();
To pick more images I use the following code (that doesn’t open the gallery, just the recent images, but it’s acceptable for me):
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);
In "OnActivityResult" I get the URI path as following:
ClipData mClipData = data.getClipData();
and in a "for":
ClipData.Item item = mClipData.getItemAt(i);
Uri imageUri = item.getUri();
To get the image orientation I use the following code:
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = getApplicationContext().getContentResolver().query(imageUri, orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Note: I tried to use the “ExifInterface” class but it always returns 0 (zero) on my Samsung S7 Android 7.0.
I noticed that the method to pick one image returns a URI path like “content://media/external/images/media/imageX”, instead the method to pick more images returns a URI path like “content://com.android.providers.media.documents/document/imageX”. I don’t know if it can be the problem.
Thank you everybody in advance.
Vincenzo

AdobeImageIntent error

I have been trying to integrate the Adobe Creative SDK in my app. I have added one extra activity which launches camera and gallery and saves the image in an ImageView.
I successfully passed the image to another activity but for using the Adobe Creative SDK you need an uri path.
After providing the uri path I am getting an error -
'AdobeImageIntent()' has private access in 'com.adobe.creativesdk.aviary.AdobeImageIntent'
here is the onCreate method -
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editor);
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imageBitmap");
String path = bmp.toString();
Uri imageUri = Uri.parse(path);
Intent imageEditorIntent = new AdobeImageIntent().Builder(this)
.setData(imageUri)
.withOutput(Uri.parse("file://" + getFilesDir() + "my-pic-name.jpg")) // output file destination
.withOutputFormaat(Bitmap.CompressFormat.JPEG)
.withOutputSize(MegaPixels.Mp5)
.withOutputQuality(90)
.build();
startActivityForResult(imageEditorIntent,1);
Intent cdsIntent = AdobeImageIntent.createCdsInitIntent(getBaseContext(),"CDS");
startService(cdsIntent);
imageView = (ImageView) findViewById(R.id.imageView);
}
why I am getting this error?
Thanks for help!
Hope I would get answers!!
Replace
Intent imageEditorIntent = new AdobeImageIntent().Builder(this)
^^^^^
with:
Intent imageEditorIntent = new AdobeImageIntent.Builder(this)
^^^^^
Possible issues with the code above
Try removing the cdsIntent and see if your code runs.
Without more information, it's hard to know, but it could be that both your cdsIntent and your imageView assignments are coming too late in onCreate().
Taking a photo from your app
You can create a new camera Intent and start it like this:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(cameraIntent, 400); // Can be any int
}
The results from the camera will come back to you in onActivityResult().
Handling the results from the camera Intent
How to handle the results will depend on what your app does. Google has a nice overview on the subject on the Android Developer Portal.
If you have further questions beyond the scope of this one, it may be good to make a new question to help get this one more focused.

how to launch photo gallery with search parameter in Android programatically

I am trying to programatically launch or open the photo gallery after passing a photo name search parameter.
I am new at this. I am thinking maybe intents can be used but not sure so I am wondering if anyone could please point me in the right direction. Preferably with some code examples.
Much thanks.
RE-EDIT
As requested, this is the code I have so far..
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// CAMERA_PIC_REQUEST = 2600;
cameraIntent = Intent.createChooser(intent,"Select Picture");
you can try follow code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(photoUri);
context.startActivity(intent);
I think this is what you mean, correct me if I'm wrong:
String nameOfPhotoToBeRetrieved = "myPhoto";
String WHERE = "TITLE ="+nameOfPhotoToBeRetrieved;
Then you can use the following line to deliver a result to your cursor/listener:
CursorLoader(context,content_uri,null,WHERE,null,null).deliverResult(myCursor);

Specify the album of a recorded video in Android

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!

Jpeg compression quality in android

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")

Categories

Resources