问题
I want to open pdf file using installed adobe reader. I tried in the following way to prevent "Complete action using" menu.
Intent intent = new Intent();
intent.setPackage("com.adobe.reader");
intent.setDataAndType(Uri.fromFile(doc), "application/pdf");
startActivity(intent);
Using the above code i managed to reduce the list size to 2. Is there any way to avoid showing context menu (Complete action using).
Thank you!
回答1:
Android system automatically displays "complete action using" dialog box when two activities have same intent filter action. Once you select the default action. Android will not display it & complete the task using default action.
回答2:
I would like to thanks every one who tried to answer this question. After some browsing i found solution for my Question. which is perfectly working for me.
instead of using
intent.setPackage("com.adobe.reader");
I used
intent.setClassName("com.adobe.reader", "com.adobe.reader.AdobeReader");
don't forget to start activity in try catch block, it helps when adobe reader not installed on Device. Please check the below snippet.
try {
Intent intent = new Intent();
intent.setClassName("com.adobe.reader", "com.adobe.reader.AdobeReader");
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(doc), "application/pdf");
startActivity(intent);
}
catch (ActivityNotFoundException activityNotFoundException) {
activityNotFoundException.printStackTrace();
}
来源:https://stackoverflow.com/questions/11536143/how-to-prevent-complete-action-using-while-opening-pdf-file-using-adobe-reader