How can I use default Android gallery to display only application's photos? Basically I need to display only my application photos on gallery.
Many Thanks
Sure! You have to parametrize the Intent that is launching the Gallery Application: Set Action to Intent.ACTION_PICK. Set MIME type to one of the image types, or image/* . Set the data to the file to be shown's Uri.
Intent galleryStarter = new Intent();
galleryStarter.setAction(Intent.ACTION_PICK);
galleryStarter.setType("image/*");
galleryStarter.setData(Uri.fromFile(imageFileToShow));
context.startActivity(galleryStarter);
Related
I use following code to open an image in the gallery:
public void onItemClicked(PictureItem item){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri imageUri = FileProvider.getUriForFile(getApplicationContext(), "myapp.fileprovider", new File(item.uri.getPath()));
intent.setDataAndType(imageUri, "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
This shows my photo in the gallery, but in a 'read-only' mode. I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Which action do I have to use for that? I do not want to use pick, just normal view with the option to delete. I tried ACTION_EDIT but it's not supported (and not quite the right choice neither ...).
I use following code to open an image in the gallery
First, there are hundreds, if not thousands, of "gallery" apps available for Android.
Second, your code simply asks to view an image (with a broken Intent due to your wildcard MIME type). There is no requirement for the app that responds to be a "gallery" app.
I want to be able to delete the image from there, just as if I opened it directly in the gallery.
Then implement that yourself, in your own app, and get rid of the ACTION_VIEW Intent.
Which action do I have to use for that?
There is no Intent action that says "please display this image, but only if you are a gallery app, and, oh, by the way, you must offer a delete option", which appears to be what you want.
i have a little problem, I need show the images/videos form a specific folder via default gallery, but when i throw the intent, the gallery not shows only files from the folder that i pass to te data intent, the gallery shows all images to the device. The code that i use is:
Uri selectedUri = Uri.parse(Environment.getExternalStorageDirectory().toString() + "/DCIM/folder/");
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setData(selectedUri);
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
I need show the images/videos form a specific folder via default gallery
That is not possible. There are thousands of device models. These ship with hundreds of different "default gallery" apps. None of them have to have some sort of API to allow you to request that they view some directory's worth of images.
Activities responding to ACTION_VIEW with a MIME type of image/* will expect that the Uri points to a single image. There is no MIME type for a directory, and there is no requirement that any gallery app honor such a MIME type even if one existed.
I am using the following code to open android gallery when an image is clicked in my app
Intent intent = new Intent (Intent.AUri.parse( "content://media/internal/images/media" ));
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
mActivity.startActivity(intent);
how can i modify my code to open a particular image directory or a particular image
According to me you should try this.
In your MainActivity introduce a method to create intend for that
and use syntax
intent.setComponent(new ComponentName("com.example.administrator.YOUR GALLERY APP NAME","com.example.administrator.YOUR APP.MainActivity"));
where com.example.administration is the initial name of your package
I want my Activity could accept jpg by Gallery.
so i set
Intent picker = new Intent (Intent.ACTION_PICK);
picker.setType ("image/jpeg");
But the gallery still shows images of all formats .
how can I let the gallery only shows what I need?
Whether I need to customize the gallery?
Currently I have the following:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(mediaLoc)), "image/" + type);
context.startActivity(intent);
This was because the app used to download images from urls and saved them into the sdcard before viewing. But now I want to change the implementation to show the image from a url in the default image viewer when ACTION_VIEW is called and give them the option to save. Is this possible with ACTION_VIEW? I'm asking because I wish to use the default image viewer in the phone as it has already handled the zoom functions.
You would have to make a custom action_view for it.