我打算用下面这段代码打开一个word文件,
public static Intent getWordFileIntent(File file){
Intent intent=new Intent(android.intent.action.VIEW);
intent.addCategory(android.intent.category.DEFAULT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri=Uri.fromFile(file);
intent.setDataAndType(uri, "application/msword");
return intent;
}
调用的代码是
Intent wordIntent= FileUtil.getWordFileIntent(file);
context.startActivity(wordIntent);
手机中存在打开word文件的app,就可以顺利打开。如果不存在打开的app,程序就会报“no Activity found to handle intent”错误。请问下是怎么回事?
你
try catch
处理一下这个异常即可。