How to prevent “complete action using” while opening pdf file using Adobe Reader.

僤鯓⒐⒋嵵緔 提交于 2019-12-13 06:48:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!