Reputation: 3
I'm trying to open a pdf file from my app , on my device currently installed 3 3rd party apps to open pdf file. when the system asks me on witch of them to open the pdf, how can i know if the user selects one and presses "ok" or "decline"? my actions defined by if he accepts or declines
This is in my class :
String path="...../file.pdf";
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "application/pdf");
startActivityForResult(intent, 225);
And then in the activity :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == 225) {
// Make sure the request was successful if (resultCode == RESULT_OK)
} else {
}
}
Upvotes: 0
Views: 433
Reputation: 25864
You can find all of the apps on the device that can service your Intent using the following code:
List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
You can use the information from this to query the packages and learn their display name and icons (SO has plenty of answers how to do that).
You can create your own Dialog from within your app that looks identical to the system dialog. In this way you'll be able to track hits and pass the intent to the selected package directly.
Good luck!
Upvotes: 1
Reputation: 43304
how can i know if the user selects one and presses "ok" or "decline"?
You can't. ACTION_VIEW
that is used to open a pdf in an external app does not give back any information. You can use startActivityForResult()
but it will not have any effect because a result will not be set. Also see ACTION_VIEW documentation.
You should redesign your concept/logic so that it does not depend on this information.
Upvotes: 0