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 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!
I have an image/pdf/docx/video as part of a listview item. I want to open them with appropriate applications in android. Currently only the video seem to open properly. Rest does not work. Can someone kindly help me !!!
Here is my code snippet I use from onItemClick in a ListView:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(itemPath), "*/*");
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
I tried :
intent.setDataAndType(Uri.parse(itemPath), "image/*");
for image files and
intent.setDataAndType(Uri.parse(itemPath), "application/pdf");
for pdf files too. But none work.
Thanks.
I would like to open a Text file launcher from my application.
I have a byte[]/base64 data, that needs to be launch in an app based on their extension. I tried launching a text file using below code, but im unable to do so. Could any one please help me on this? Here is my code:
Uri myUri = Uri.parse(mActionResponse.getAttachmentData()); //mActionResponse.getAttachmentData() will return byte []
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setDataAndType(myUri, "text/plain");
context.startActivity(intent);
FYI i dont want to save the file in device storage.
I am using the below code which opens up the Gallery, Music Player, Dropbox and Contacts, i want the My Files folder to get open programatically, please let me know if there are any specific intent parameters i need to pass to get the File Manager open.
if it is not possible through intent then please give me a snippet or an hint to open the My Files folder programatically.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
Intent i = Intent.createChooser(intent, "View Default File Manager");
startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);
Thanks.
You can use this code to file the files.
int PICKFILE_RESULT_CODE=1;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent,PICKFILE_RESULT_CODE);
this will help you to browse the files from your storage.
Its best that you include a library in your project which handles this scenario.
This worked for me:
This library shows the list of third-party apps. It also has its own file browser for selecting files.
Bad thing is, most Android distributions may or may not ship with a file manager, and even so, may be not with the one which handles CHOOSE_FILE_REQUESTCODE.
So, you are left to create your own file picker activity. Luckily there are many ready made ones available:
http://code.google.com/p/android-filechooser/
https://developers.inkfilepicker.com/docs/android/
If you want to open samsung My Files application try this below code.
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
You have to specifically mention the package name of the explorer application. Please find the example below to open a specific folder in ES Explorer.
public void openfolderInexplorer(String path){
Intent intent = this.getPackageManager().getLaunchIntentForPackage("com.estrongs.android.pop");
if (intent != null) {
// If the application is avilable
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.parse(path);
intent.setDataAndType(uri, "resource/folder");
this.startActivity(intent);
} else {
// Play store to install app
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=" +
"com.estrongs.android.pop"));
this.startActivity(intent);
}
try this below code. if any file manager available , then it will pop up in a form of menu to choose appropriate for the user.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);