I have an app that needs to open an XPS file.
I can use the code below to fire an Intent to open the file, however I want to know if there is a way to check if there are any apps on the phone that can handle the request to open this file.
The idea is that if no app on the phone can open an XPS file, I can prompt the user to download an app to open the XPS file.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(fileURL.toURI());
intent.setDataAndType(Uri.fromFile(file), "application/vnd.ms-xpsdocument");
//intent.setDataAndType(Uri.fromFile(file), "application/*");
startActivity(intent);
Any ideas?
I've never used it but I think you can do this using PackageManager.queryIntentActivities(...)
Create the Intent you'd normally use for opening an XPS file and call that method. If the returned List<ResolveInfo> is empty then there are no activities registered for handling XPS files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With