I wish to select a video from User's gallery app, but I'd like to have one of the directories hidden from the video picker.
Directory "abc/" is visible in user's default gallery
In my app, user will pick a video from gallery
When he's picking a video using his gallery, directory "abc/" won't be visible.
What I currently do shows all directories available in the user gallery:
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
i.setType("video/*");
startActivityForResult(i, MainController.SELECT_VIDEO_REQUEST);
Is there any option that I could add to the intent to prevent my "abc" directory from being visible at picking time?
Is there any option that I could add to the intent to prevent my "abc" directory from being visible at picking time?
Not using ACTION_PICK. You are delegating this work to one of many possible apps. There are no documented extras for the Intent for "please hide this directory" or "please hide all videos whose names contain the letter 'q'" or anything like that. And, even if there were such an extra, apps implementing ACTION_PICK would be free to ignore it.
There are existing libraries for choosing files; one might meet your needs.
Just before you start the picker intent create an empty file with the name .nomedia in the abc directory.
In onActivityResult() delete the file again.
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.
As the title suggests, i'm having an option to upload an image in my app.
I would like to have two options: Click a new picture & Select from gallery.
Gallery selection is working fine on all devices using this code:
Intent in = new Intent();
in.setType("image/*");
in.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(in, getString(R.string.selectpicture)), 100);
The problem is with Click a new picture.
I want to use other camera apps installed on the device to get the image.
This code should save the image user clicks at the specified path.
Intent m_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
imageUri = getImageUri();
m_intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(m_intent, REQUEST_IMAGE_CAPTURE);
But what happens is, the EXTRA_OUTPUT is not respected by all camera apps.
Also if memory is low, my app is killed by the system which makes things more complicated.
So, what's the best way to enable user to click a new picture and get the image path in my app?
If using third party libraries is better, which one's are reliable?
the EXTRA_OUTPUT is not respected by all camera apps.
Any time you delegate anything to a third party app, you can run into problems.
Also if memory is low, my app is killed by the system which makes things more complicated.
You need to handle this anyway. Save the value you put in EXTRA_OUTPUT in the saved instance state Bundle.
what's the best way to enable user to click a new picture and get the image path in my app?
If you wish to stick with ACTION_IMAGE_CAPTURE, I'd go with this triage:
If there is an image in the location you provided to EXTRA_OUTPUT, use it
If not, and getData() on the Intent given to you in onActivityResult() returns a Uri (and not null), use that (and if you truly need a File, use ContentResolver and openInputStream() with the Uri and copy the contents into your own file)
If neither are true, and getParcelableExtra("data") returns a value, save that Bitmap to a file
If none of those are true, suggest to the user to get a different camera app, perhaps pointing them to one that you have tried and know works
Or, take the picture yourself, directly or using a library like mine.
I'm going to develop a simple app to list .jpg files and after a click call an Intent.ACTION_VIEW, below the code:
File imageFile = new File(filename);
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(imageFile), "image/jpeg");
startActivity(i);
The intent works properly, in fact in app I receive the message to select an app to show the selected image. But I noticed that after the choice, for example with Google Photos, not all function are enabled. For example the share function is not visible, has someone already noticed this behavior?
Some other details; if I choose Google Photos I only have the "Info" and "Guide and Feedback" options. If I choose gallery app (I have a Samsung Ace 3) I have only "Info" and "Set as wallpaper" options.
Note: if I open the same image directly from Google Photos all functions are enabled...
The ACTION_VIEW intent calls another application to view the content that you present, in your case a JPEG image. If there is more than on application that can handle that Intent, Android lets the user choose an app to display the image. Once the application receives the Intent, it is up to that application to display the content how it sees fit.
Basically, you have no control over what functions are available with Intent.ACTION_VIEW. If you want more control, you can create your own Activity in which you can view the image and provide whatever functions you would like.
I've a button on which I would like to open any file manager, and allow user to pick ONLY audio files. So i wrote something like this:
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select audio", SELECTED_AUDIO);
However, this doesn't work - it opens file manager (in my case Astro) and voalaaa - I can see and also pick any files I want - I mean, text files, video files, etc. Simple it doesn't filter or check anything...What am I doing wrong? Or its fault of Astro? I just want to show only audio files, or show all files but allow to pick only audio.
What am I doing wrong?
Nothing.
Or its fault of Astro?
Sort of. You assume that Astro knows the MIME type of all its files, and that it will actually use the MIME type to filter the results. There is nothing forcing Astro to do either of those things. The same holds true for any file manager or anything else that responds to ACTION_GET_CONTENT for audio/*. Now, it would be nice if Astro would do the filtering or something, but that's an issue you would have to take up with them.