file chooser for Nougat or higher - android

I am implementing a file chooser in my android app, I am having 3 different file chooser each for AUDIO, VIDEO, IMAGE.
Its working good below android 7.0, when clicked, its going to gallery for choosing that type of file.
But in Android 7.0, when i am clicking to choose the file picker, its going to RECENT and from there manually i need to go to audio or image gallery, how can i directly go to audio gallery on clicking file chooser as its working in kitkat.
Below is my code to call the file chooser --
private void showFileChooser() {
Intent intent = new Intent();
//sets the select file to all types of files
intent.setType("audio/*");
//allows to select data and return it
intent.setAction(Intent.ACTION_GET_CONTENT);
//starts new activity to select file and return data
startActivityForResult(Intent.createChooser(intent,"Choose File to Upload.."),PICK_FILE_REQUEST);
}

Related

Android - how to open image in gallery with delete option

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.

ACTION_GET_CONTENT does not allow moving or deleting files

I'm trying to use Intent ACTION_GET_CONTENT to open an application such as (File Manager, File explorer etc...). However once I am in the File Manager, I am only able to open the file. The Copy to.. and Move to... capabilities are not shown when opening File Manager app using this method. Is ACTION_GET_CONTENT only used for opening files?
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath());
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
Here is the image showing the open option only:

Open file manager to a specific location from my app (Android)

I am making an app that downloads a file. After the file finishes downloading, the user can press a button that will open the file location in their default file manager.
I don't want to use intents as it causes the file manager to act like a file chooser! I do NOT want a file picker. My app should get lost after the user clicks on the button after showing him the downloaded location. I will figure out destroying my app later but first I want to fire up the default file manager and point it to the downloaded location. Let me know how to do this.
I used this code but it acts like a file picker.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //tried ACTION_VIEW but it says no apps that can perform this action!
Uri uri = Uri.fromFile(mDownloadDir); //mDownloadDir is file object
intent.setDataAndType(uri, "resource/folder");
mContext.startActivity(Intent.createChooser(intent, "Open folder"));

Cannot Show images with gallery app in android

I want open my images with gallery app but show this error
Cannot generate thumbnail
my code:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(Environment.getExternalStorageDirectory().getPath()+"/Connection/Picture/"+listItems.get(position)), "image/*");
startActivity(intent);
Is there another way to show image with default android app?
Notice:
1.when I use a file manager to open it , it open successfully
2.when I use my app to open image ,if I choose another app to open it,it open successfully
3."listItems.get(position)" is imagename forexample "2361386837.jpg"
Can You help me?

how to open other file manager apps via intent?

in my app i use the code below to open up the downloads and only see PDF files. But it opens up the default Android file manager and for other parts of my app to work i need to use other file managers (i am using ES File Manager) to open up instead.
How do i open up other file manager apps?
(giving the user an option to choose from multiple file manager apps helps too)
My code as of now:
public void PDF() {
PDF = (Button) findViewById(R.id.FindPDFBtn);//Finds the button in design and put it into a button variable.
PDF.setOnClickListener(//Listens for a button click.
new View.OnClickListener() {//Creates a new click listener.
#Override
public void onClick(View v) {//does what ever code is in here when the button is clicked
Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select a PDF "), SELECT_PDF);
}
}
);
}
The problem with third party file explorers is that most of them don't support the same kind of intents (as they are not standardized).
For ES File explorer, check this: http://www.estrongs.com/res/develop_en.htm

Categories

Resources