您的位置:首页 > 其它

打开各种文件(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类型是打开邮箱,但是你手机里面没装邮箱客户端,就会报错。

    

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: