How can I upload photos from Android's mobile gallery? - android

I want to upload photos from Android's mobile gallery from my app. How can I do that?

You should use the MediaStore to be able to get pictures from the gallery:
http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html
Edit:You can get the image with this:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 1);
And you get the bitmap with this in your onActivityResult :
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity()
.getContentResolver(), data.getData());

Related

Open gallery except .gif images

I want to open device gallery except .gif images.
I tried the following code but it showing all images in gallery, let me help
Intent pickPhoto = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if(Build.VERSION.SDK_INT >21){
pickPhoto.setType("image/*");
pickPhoto.setAction(Intent.ACTION_GET_CONTENT);
}
startActivityForResult(pickPhoto, PICK_FROM_GALLERY);
To open the device gallery except for .gif images, you need to set the supported mimeTypes for the gallery intent i.e., image types you need to pick from the gallery like png, jpg, jpeg, etc.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
String[] mimeTypes = {"image/png", "image/jpg", "image/jpeg"};
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, REQUEST_GALLERY);

Choose a picture from the gallery only, not other application like Photos App

I am trying to pick an image from the Android Gallery only, not other applications like Photos, file manager etc
I need a solution to open the Gallery App directly, or is it possible to use the Photos Application to pick image?
1) Choose from gallery
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent,CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
2) onActivityResult result code
try {
// bimatp factory
BitmapFactory.Options options = new BitmapFactory.Options();
// downsizing image as it throws OutOfMemory Exception for larger images
options.inSampleSize = 2;
final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),options);
descimage.setImageBitmap(bitmap);
bitmap.compress(CompressFormat.JPEG, 80, new FileOutputStream(new File(fileUri.getPath())));
photostatus = 1;
pbar.setVisibility(View.VISIBLE);
txtbrowser.setEnabled(false);
new upload().execute();
} catch (NullPointerException e) {
e.printStackTrace();
}
You should be aware that Gallery no longer exists on some devices running Lollipop. The photos app is the replacement and it should have no problems handling the intent to select an image. Intent.ACTION_GET_CONTENT is usually recommended for selecting images, such as:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, ID);
Opening the gallery on devices that do have it installed is discussed here. Basically every different vendor may ship a different gallery app.
It is possible to launch a specific activity for an implicit intent (such as selecting an image) without showing the chooser dialog by using the PackageManager.queryIntentActivities() API to iterate all the available packages on the users device so you can explicitly launch the one you require.
This intent allows you to pick the image from the default gallery.
// in onCreate or any event where your want the user to select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
For receiving the selected image in onActivityResult()
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
}
}
}
i got the solution from here

my image is not displayed

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.

How to get picasa picture thumbnail

Getting an image from the Gallery with
Intent intentGallery = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intentGallery, CHOOSE_PICTURE);
and
Uri targetUri = data.getData();
Log.v(LOG_TAG,"Data achieved from gallery: "+ targetUri);
results in content://com.android.sec.gallery3d.provider/picasa/ if the user selected a Picasa image.
This solution is not good for me, because i don't want to use internet.
So, there is a way to pick only the local picasa image thumbnail from gallery?

Downloading images from the gallery in android

I am developing an app in which i need to import images from the default gallery to the storage in sd card that I use for the app. Is it possible?
You can use an Intent to have the user pick an image from the default gallery.
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
photoPickerIntent.setType("image/*");
Uri path = getTempUri("/mnt/sdcard/yourfolder");
photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, path);
photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
startActivityForResult(photoPickerIntent, filenameInt);
This will save the image picked by the user to the path you specified. There are some more options like cropping and scaling:
photoPickerIntent.putExtra("crop", "true")
.putExtra("aspectX", 4)
.putExtra("aspectY", 3)
.putExtra("outputX", 800)
.putExtra("outputY", 600)
.putExtra("scale", true);
I don't know if this is exactly what you're aiming for though.

Categories

Resources