2012-05-10 31 views
0
String mimetype = ".docx\tapplication/vnd.openxmlformats-officedocument.wordprocessingml.document"; 
File file = new File(FilePath, filename); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(file), mimetype); 
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

我使用上面的代碼來讀取.docx文件。
如何檢查應用程序是否可以支持文件格式?
如果沒有,下面的消息:如何檢查文檔文件是否可以在Android中支持

Toast.makeText(this, "Not be supported.", Toast.LENGTH_LONG).show(); 

回答

1

讓這樣的功能,並給它你的意圖。它會檢查是否有任何應用程序能夠處理此意圖。

private boolean isIntentLaunchable(Intent intent) 
{ 
    PackageManager packageManager = getPackageManager(); 
    List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); 

    if (activities.size() > 0) { 
     return true; 
    } 

    return false; 
} 
相關問題