Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我想从服务器下载该文件,并在android中查看该文件,其中包含各种文件扩展名,如(pdf、doc、mp4、jpeg))_Java_Android_Pdf - Fatal编程技术网

Java 我想从服务器下载该文件,并在android中查看该文件,其中包含各种文件扩展名,如(pdf、doc、mp4、jpeg))

Java 我想从服务器下载该文件,并在android中查看该文件,其中包含各种文件扩展名,如(pdf、doc、mp4、jpeg)),java,android,pdf,Java,Android,Pdf,我想从服务器下载该文件,并在android中查看该文件,其中包含各种文件扩展名,如(pdf、doc、mp4、jpeg) 我试过这个 Intent intent = new Intent(Intent.ACTION_VIEW); File file1 = new File(Environment.getExternalStorageDirectory(),"report.pdf"); intent.setDataAndType( Uri.fromFile( file1

我想从服务器下载该文件,并在android中查看该文件,其中包含各种文件扩展名,如(pdf、doc、mp4、jpeg) 我试过这个

Intent intent = new Intent(Intent.ACTION_VIEW);
       File file1 = new File(Environment.getExternalStorageDirectory(),"report.pdf");

       intent.setDataAndType( Uri.fromFile( file1 ), "application/.*" );


     startActivity(intent);
但没有成功 我应该在这张表上单独加上分机吗
请建议解决此问题的方法参见此代码以供参考

filePath是文件的实际路径

                        Uri fileUri = Uri.fromFile(new File(filePath));

                        Uri new_uri = Uri.parse("file://"
                                + fileUri.getPath());

                        Intent intent = new Intent(Intent.ACTION_VIEW,
                                new_uri);

                        MimeTypeMap myMime = MimeTypeMap.getSingleton();
                        String fileExt = filePath.substring(filePath
                                .lastIndexOf(".") + 1);
                        String mimeType = myMime
                                .getMimeTypeFromExtension(fileExt);
                        intent.setDataAndType(new_uri, mimeType);

                        startActivity(intent);