I'm new to intentions, and I'm trying to figure out how to use parsing (URI) and / or setType () to get the right types of applications to open and let me choose things.
I want to start the intention of your application, which will allow the user to select one of the many file types ( .PDF, .DOCX, .XLSX, .PPTX, .DOC, .JPG, .PNG, .TXT, .LOG, etc.). I need an operation to return - this is the full path to this file.
I am currently using setType("*/*")with the selection I found here, but this automatically opens up some document selector in Android. I have a file manager and other applications, and you want to know what the standard setType type or MIME type is. Thanks in advance.
In addition, I apologize if this has already been answered. I looked online, but I think I was looking for the wrong thing, because the results that I get are for intentions that simply want one of them or do not return the path.
My applicable code is below: (Note: this is done inside the snippet)
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);
}
}
}