Вы можете проверить это с помощью файла Android MIME type
. Ссылаться на следующий код
Dictionary<string, string> matchArray = new Dictionary<string, string>();
matchArray.Add(".3gp", "video/3gpp");
matchArray.Add(".apk", "application/vnd.android.package-archive");
matchArray.Add(".doc", "application/msword");
matchArray.Add(".gif", "image/gif");
matchArray.Add(".wps", "application/vnd.ms-works");
matchArray.Add(".pdf", "application/pdf");
matchArray.Add(".ppt", "application/vnd.ms-powerpoint");
matchArray.Add(".png", "image/png");
//...
public void OpenFileByPath(Context context, string path)
{
if (context == null || path == null)
return;
string type = "";
foreach (string key in matchArray.Keys)
{
if (path.Contains(key))
{
type = matchArray[key];
break;
}
}
if (type == "")
{
//there is no app can open the file ,do some you want
}
else
{
// open your file
}
}
Вы можете добавить дополнительные значения ключа о типе MIME, выполнив поиск в Интернете