Java 我想从服务器下载该文件,并在android中查看该文件,其中包含各种文件扩展名,如(pdf、doc、mp4、jpeg))
我想从服务器下载该文件,并在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
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);