由文件的路径通过其他应用打开图片,PPT,Word,excel,PDF

来源:互联网 发布:淘宝代购海外直邮真假 编辑:程序博客网 时间:2024/04/28 17:31
1.打开图片
                    Intent intent = new Intent(Intent.ACTION_VIEW);                    intent.setDataAndType(Uri.parse("file://"+"/sdcard/test.jpg"),"image/*");                    startActivity(intent);

2.打开PPT,Word,excel文件

                    Intent intent = new Intent(Intent.ACTION_VIEW);                    //intent.setDataAndType(Uri.parse("file://"+file_path),"application/vnd.ms-excel");                    intent.setDataAndType(Uri.parse("file://"+file_path),"application/msword");                    startActivity(intent);

3.打开PDF文件

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf");Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(Uri.fromFile(file), "application/pdf");intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);startActivity(intent);

                                             
0 0
原创粉丝点击