以下是我的代码
Intent intent = new Intent(Intent.ACTION_VIEW);
File file = new File(SDCardRoot,filename);
intent.setDataAndType(path, "video/quicktime");
try {
startActivity(intent);
}
catch (ActivityNotFoundException ex) {
}
当我尝试播放mov文件格式并替换为我自己的错误打开句子时,有没有想过如何捕获msg而不显示sorry, this video cannot be played
?
答案 0 :(得分:1)
您当前正在捕获'ActivityNotFoundException',因此不会捕获其他异常。您必须将ActivityNotFoundException更改为更通用的(例如'Exception')或添加另一个catch子句
解决方法1:
try {
startActivity(intent);
}
catch (Exception ex) {
}
溶液2:
try {
startActivity(intent);
}
catch (ActivityNotFoundException ex) {
}
catch (...<insert your particular exception type here>...) {
}