打开各种文件(setDataAndType)
2014-10-11 09:44
405 查看
private void openFile(File file){
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//设置intent的Action属性
intent.setAction(Intent.ACTION_VIEW);
//获取文件file的MIME类型
String type = getMIMEType(file);
//设置intent的data和Type属性。
intent.setDataAndType(/*uri*/Uri.fromFile(file), type);
//跳转
startActivity(intent); //这里最好try一下,有可能会报错。 //比如说你的MIME类型是打开邮箱,但是你手机里面没装邮箱客户端,就会报错。
}
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//设置intent的Action属性
intent.setAction(Intent.ACTION_VIEW);
//获取文件file的MIME类型
String type = getMIMEType(file);
//设置intent的data和Type属性。
intent.setDataAndType(/*uri*/Uri.fromFile(file), type);
//跳转
startActivity(intent); //这里最好try一下,有可能会报错。 //比如说你的MIME类型是打开邮箱,但是你手机里面没装邮箱客户端,就会报错。
}
相关文章推荐
- android 打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- Android(java)学习笔记143:android提供打开各种文件的API接口:setDataAndType
- android 打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- android 打开各种文件 intent.setDataAndType
- andriod打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)转:
- android 打开各种文件(setDataAndType)
- 笔记112--Android打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- android 打开各种文件(setDataAndType)
- android打开各种文件(setDataAndType)
- Android通过setDataAndType(uri, "type")打开文件