Android Studio - Open epub + pdf files from default directory application (Programmatically) - android

How to open default file manager app that let you choose a file but only with extension .epub or .pdf programatically via Intent?

The code shown is the declaration of the intent that you have to start for opening the default file manager app that let you choose a file but only with extension .epub or .pdf, I hope it will be useful.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/epub+zip");
String[] mimetypes = {"application/epub+zip", "application/pdf"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent,PICKFILE_RESULT_CODE);
It is a mix of solutions I found that work so maybe it is redundant. Let me know what you think!

Related

Android open file manager how to show only particular file only

I am facing an issue while opening the File Manager from Android apps.
I want to see only particular file only which I have specific but I am able to see other file also but it is not highlight it is been grey out but how to hide that also so only particular specific file I can see no other file.
Below code which I have used:
Intent intent = new Intent(Intent.Action_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES,"application/pdf");
startActivityForResult(intent, FILE_REQUESTED);
What can I do to fix this?
I want to see only particular file only
Sorry, that is not an option with ACTION_OPEN_DOCUMENT.

ACTION_GET_CONTENT supported mime types?

I'm trying to use ACTION_GET_CONTENT with text/csv mime type but the result is that all files are displayed but grayed out in the file picker?
Here is my code:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/csv");
...
currentActivity.startActivityForResult(intent, READ_REQUEST_CODE, Bundle.EMPTY);
Tested on Android 7.1/8/9 with the same outcome. The following directory contains .json and .csv files.
Is this mime type even supported?
I don't think a csv is explicitly supported, instead you can just treat it as a normal plaintext file, and parse the content yourself like this:
intent.setType("text/*");
The downside is that the non-csv files will also be shown to the user, therefore, you might need to do some extra checking for the contents of the file.
If you really do need it to be a .csv being shown to the user, you can create your own file picking activity that filter everything else that does not have the .csv extension.
I have the same problem. Android seems to only recognize "text/comma-separated-values". Here's how I fixed it,
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
String[] mimetypes = {"text/csv", "text/comma-separated-values"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);

Create File Explorer for PDF, Text and Image in Android

I am new in android development and I just want to know how to do a customized file explorer that will only display pdf, text and image files.
I tried this example but I dont know how to filter the files that can be displayed :(
Android File Explore
Is there a way to display and select only the files mentioned above?
Take a look at #Smitted answer.
Create the intent:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
You can set the MIME types for the intent:
intent.SetType("application/pdf");
and add additional MIME types:
String[] mimetypes = {"image/*", "text/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
and start the activity:
StartActivityForResult(intent, FIND_FILE_REQUEST_CODE);
You can filter the files in the accept() of new FilenameFilter().

How to open File manager navigated to specific directory in android?

I want to show downloaded file in File Manager by giving the File absolute Path.I read a lot about it and find same thing
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(file.getAbsolutePath());
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
And it results to view only recent files that has been viwed. Please guide to Open File Manager while navigating it to file whose absolute path has been given.
I read a lot about it and find same thing
ACTION_GET_CONTENT has little to do with a file manager.
Please guide to Open File Manager while navigating it to file whose absolute path has been given.
There is nothing on Android for this, sorry.

Android Custom FileChooser

In my app the user has the opportunity to import a file via an intent.
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(new Helper(FunctionsActivity.this).getPathToAppFolder());
chooseFile.setDataAndType(uri, "*/*");
chooseFile.setType("*/*");
Intent intent = Intent.createChooser(chooseFile, getString(R.string.importDatei));
startActivityForResult(intent, REQUEST_CODE_IMPORT_FILE);
The valid files are files with the ending: .tr
These can undestood by my app.
The problem is, that the Intent shows all files in the folder:
After long searching I could not find a solution to show only .tr files. (Besides: For .xml or known file formats it is possible.)
So my idea is to write a small custom filechooser. When you click on "import", an activity opens that shows the names of all files with the extension .tr
So my question is:
Has anyone implemented something like this and can help me or does anyone has tips how to implement this the best?
I am grateful for everything that helps me further

Categories

Resources