I am new to intents and I am trying to figure out how to use parse(URI) and/or setType() to get the right types of application to open up and allow me to select things.
I want to launch an intent from my app that will allow the user to pick one of many types of files (.PDF
, .DOCX
, .XLSX
, .PPTX
, .DOC
, .JPG
, .PNG
, .TXT
, .LOG
, etc.). What I need the activity to return is a full path to that file.
Right now I am using setType("*/*")
with a chooser that I found on here, but this is automatically opening some documents selector in Android. I have file manager and other apps, and want to know what the standard setType is or MIME type. Thanks in advance.
Also, I apologize if this has already been answered. I have looked online, but think I am searching for the wrong thing because the results I am getting are for intents that just want one of these or don't return the path.
My applicable code is below: (Note: this is being done inside a fragment)
static final int PICK_FILE_REQUEST = 101;
private String pathToFile = "";
public String selectFile() {
String path = "";
Intent intent = new Intent(Intent.ACTION_GET_CONTENT), chooser = null;
intent.setType("*/*");
chooser = Intent.createChooser(intent, "Find file to Print");
startActivityForResult(chooser, PICK_FILE_REQUEST);
path = pathToFile;
return path;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PICK_FILE_REQUEST){
if(resultCode == Activity.RESULT_OK){
pathToFile = data.getDataString();
String temp = data.getStringExtra("path");
Log.d("Files Fragment: ", pathToFile);
Log.d("Files Fragment: ", temp);
}
}
}