2012-01-10 76 views
3

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

這個想法是,如果手機上沒有應用程序可以打開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); 

任何想法?

回答

4

我從來沒有用過,但我認爲你可以使用PackageManager.queryIntentActivities(...)

創建Intent你通常用於打開XPS文件,並調用該方法做到這一點。如果返回的List<ResolveInfo>爲空,則不會註冊用於處理XPS文件的活動。

相關問題