簡體   English   中英

Android:檢查是否存在可以打開xps文件的應用程序

[英]Android: Check if any app exists that can open an xps file

我有一個需要打開XPS文件的應用程序。 我可以使用下面的代碼來觸發Intent來打開文件,但是我想知道是否有辦法檢查手機上是否有任何可以處理打開此文件的請求的應用程序。

這個想法是,如果手機上沒有應用程序可以打開XPS文件,我可以提示用戶下載應用程序以打開XPS文件。

    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); 

有任何想法嗎?

我從來沒有使用它,但我認為你可以使用PackageManager.queryIntentActivities(...)來做到這一點

創建您通常用於打開XPS文件並調用該方法的Intent 如果返回的List<ResolveInfo>為空,則沒有注冊用於處理XPS文件的活動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM