I have a listview populated with some files,there can be various types like pdf or documents.When a user clicks on one i get the file mime type and start an intent that let's the user choose which application to use to open that file.What i want is to know is a user choosed something,or simply pressed back and didn't choose anything. What i tried untill now was doing a startActivityForResult and checking for success,but it returns always RESULT_CANCELED
static final int SELECTED_VIEWER = 1;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(filePath), mimetype);
try {
startActivityForResult(intent, SELECTED_VIEWER);
}catch (ActivityNotFoundException e) {
Toast.makeText(getActivity(),
Strings.ERROR_NO_VIEWER,
Toast.LENGTH_SHORT).show();
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SELECTED_VIEWER) {
if (resultCode == Activity.RESULT_CANCELED ) {
//do something
}
}
}
I even tried with an startActivityForResult(Intent.createChooser but still to no avail. How can i know if the user choosed something on that list,or if he cancelled the open?
try this..
As written in Android Developer on Activities
You can't count on action views returning what you would expect,so what i did was implement a custom alert dialog that shows all possible applications that can open a certain file,a slightly modified version as shown here Custom intent chooser
Code for those wondering,it takes a filePath as parameter and shows you all installed applications that can handle that filetype by getting the mimetype.Works with fullpaths.Can be called with
this is the class,it can take an optional delegate aswell for activity callbacks
try