[英]I want to download the file from server and view the file in android with various file Extensions like (pdf,doc,mp4,jpeg))
I want to download the file from server and view the file in android with various file Extensions like (pdf,doc,mp4,jpeg) i have try this 我想从服务器下载文件,并在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);
but no success should i have to give the individual extension in this please suggest the way to solve this 但是我没有必要在此方面给予任何扩展,请提出解决此问题的方法
See this code for your reference 请参阅此代码以供参考
filePath is a actual path of the file 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.