Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
getActivity().startActivityForResult(i, 100);
//on activity result now Uri selectedImageURI = data.getData();
Picasso.with(rootView.getContext()).load(selectedImageURI.toString()).into(image);
Okey simply, I call to open the gallery.Once opened i need to retrive image, its working in case of some pictures and in case of others not.
I noticed those others are images deleted from my phone? why are they showing?
ITS GIVing me uri content://com.google.android.apps.photos.contentprovider/-1/1 ...its the -1 ones not working always. I do not get any crash either.
I noticed those others are images deleted from my phone? why are they showing?
Because MediaStore does not know that the images were deleted, apparently. Whatever deleted them did not tell the MediaStore to update its index. Eventually, MediaStore will find this out and will filter them from its index, so the user cannot choose them via ACTION_PICK.
Related
Currently I have the following code that allows a user to choose an image.
int requestCode = 1337;
Intent chooserIntent = new Intent(Intent.ACTION_GET_CONTENT);
chooserIntent.setType("image/*");
chooserIntent = Intent.createChooser(chooserIntent, "Please choose a picture");
chooserIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(chooserIntent, requestCode);
My question is:
does Android guarantee that the returned Uri is always pointing to a location on disk, or is it possible that it might be pointing to somewhere on the internet too?
P.S. although I am not sure about this, the Uri returned by this piece of code seems to always start with content:// - I am not sure whether or not this holds for all possible return values, I thought I would just add this here to help out any possible question answerers.
does Android guarantee that the returned Uri is always pointing to a
location on disk, or is it possible that it might be pointing to
somewhere on the internet too?
It is possible to have Uri other than local disk i.e. it can be remotely as well. You will get URL from remote then convert it to Uri and use it.
From official docs:
An ACTION_GET_CONTENT could allow the user to create the data as it
runs (for example taking a picture or recording a sound), let them
browse over the web and download the desired data, etc.
Convert Url to a Uri (Reference):
Uri uri = Uri.parse( "http://www.facebook.com" );
My application is capable of capturing images and saving them (in the public Pictures directory, retrieved by Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).
Now, I want to be able to display those images in the system's gallery application. In order to achieve that, I create an Intent like this (filePath is a String containing the image's path):
Intent viewIntent = new Intent();
viewIntent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(filePath));
viewIntent.setDataAndType(uri, "image/jpeg");
startActivity(Intent.createChooser(viewIntent, null));
Displaying an image this way works perfectly fine, but the gallery's Share functionality doesn't seem to work:
When I press the Share-button, I get to choose the app I want to share to; but once I select it, nothing happens, as if the target application does not receive any data.
Is there any explanation why this behaviour occurs and how it can be fixed?
Edit: I used Intent Intercept to capture the Intent created by the Gallery/Photos app:
what is the correct way how I should form the intent to show content from my app in 3rd party viewers? I need to show images in gallery (or any other image viewer), pdfs in some pdf reader,..
Data gets server through a content provider which implements the openFile() method and returns a output pipe..
ParcelFileDescriptor[] pipe=ParcelFileDescriptor.createPipe();
...
ParcelFileDescriptor.AutoCloseOutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]);
PipeThread pipeThread = new PipeThread(fileContents, stream);
pipeThread.start();
return pipe[0];
For images I use this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, uri);
I'm creating then a chooser for this intent as usual that's not the issue..
My problem is that although I see for example the Photos app in the chooser, I just cannot open the file in it..It just only opens the gallery with my images.
It's working when I use the action send, apps like gmail, drive, dropbox,..all of them are able to correctly read the image from the provider.
Also Skitch seems to be the only one app which I have tested it on that is able to open the image also using the Intent.ACTION_VIEW action..
Please don't tell me I should just send the URI, I really need to provide the file as a stream, or somehow as a serie of bytes (IPC limitations would be probably against this). I can't save the file to a public directory.
So the issue was that have been setting Intent type and data in two separate method calls..
What I didn't know is that Intent.setType() clears its data and Intent.setData() clears its type..
When I set both data and type through the Intent.setDataAndType() method call, it works even for URI pointing to a stream.
Unfortunately the final implementation is still not working flawlessly everywhere.
It works in default android gallery app, in G+ Photos app, in QuickPic, in Sony gallery app, but it does not work in default HTC gallery neither in default Samsung gallery.
Its just a pity, that its actually not that much dependent on my implementation as on how is it implemented in the 3rd party viewer app.
I am facing a weird problem.
I have a form in my app where user will input some details and then select an image.
On pressing Submit, an email intent will be fired which will create an email draft with user's input pasted in mail body and his selected image attached to the email.
I have some code which works for Kindle Fire 1st Gen as well as other Android devices too. But the same does not work on Fire HD-7.
Here is the code to fire image selection intent.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "Select Media"), SELECT_MEDIA);
On 1st Gen Fire this works fine and returns:
content:///mnt/sdcard/Download/naturewallpapers252862529.jpg
But on Fire HD-7, it returns:
file:///mnt/sdcard/Android/data/com.amazon.photos/files/Pictures/Shared/naturewallpapers252862529 (7).jpg
And here's the most irritating fact:
CASE 1) On HD-7, if I select image from gallery, it creates a copy of the selected at "/mnt/sdcard/Android/data/com.amazon.photos/files/Pictures/Shared/" and returns this path which does not work with my code to create email intent with attachment. Also, it creates a new copy with (1), (2) and so on for same image every time I select the same image.
CASE 2) On HD-7, if I select image from ES File Explorer then everything works fine. It returns content:///mnt/sdcard/Download/naturewallpapers252862529.jpg uri with content:// scheme as against file:// in selected from gallery.
I am really out of any clues to get this resolved. Struggling since more than a week now.
Any help, any clues are highly appreciated.
Thanks,
Yogesh.
I want the user to be able to select from ALL images - those included with my app aswell as any they may have on their sdcard. For example, I have a .jpg file called cat.jpg in the data/com.mypackage/files folder, but it will not show in the list of images. This is the code I used, but it only displays images on the sdcard:
// Open up a gallery browser
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
I know that I could have two screens, one showing my images and another showing those from the sdcard, but I would rather have all of pictures in one gallery list.
Any ideas?
Thank you.
update:
Since no one has responsed, then maybe this type of task just can't be done. I cannot find any documentation one way or the other. If someone knows where the gallery view gets its data, please let me know (docs just says images - not the source of them). Or if it is not possible to combine all images from both the phone and the sdcard in one display, I would appreciate that response also.
Thanks again.