笔记-Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)
打开后缀.apk的文件。即启动安装程序。
//apkFilePath 文件路径
public void installAPK(String apkFilePath) {
// 创建URI
Uri uri = Uri.fromFile(new File(apkFilePath));
Intent intent = new Intent(Intent.ACTION_VIEW);
// 设置Uri和类型
intent.setDataAndType(uri, "application/vnd.android.package-archive");
// 运行安装
mContext.startActivity(intent);
}
/**
* 打开多种类型文件
* @param path 文件路径
* @param type 文件类型
*/
public void openText(String path , int type){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(path ));
//推断文件类型
if (FILE_TYPE_PPT == type) {
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
} else if (FILE_TYPE_WORD == type) {
intent.setDataAndType(uri, "application/msword");
} else if(FILE_TYPE_EXCEL == type){
intent.setDataAndType(uri, "application/vnd.ms-excel");
} else if(FILE_TYPE_TXT == type){
intent.setDataAndType(uri, "text/plain");
} else if(FILE_TYPE_PDF == type){
intent.setDataAndType(uri, "application/pdf");
} else if(FILE_TYPE_HTML == type){
Uri htmluri = Uri.parse(path).buildUpon().encodedAuthority("com.android.htmlfileprovider")
.scheme("content").encodedPath(path).build();
intent.setDataAndType(htmluri, "text/html");
}
try {
activity.startActivity(intent);
} catch (Exception e) {
Toast.makeText(mContext, "设备中没有安装支持该格式的程序", Toast.LENGTH_SHORT).show();
}
}
<pre name="code" class="java"> ////////打开多媒体类型
intent.setDataAndType(uri, "audio/*"); //音频
intent.setDataAndType(uri, "video/*"); //视频
intent.setDataAndType(uri, "image/*"); //图片
intent.setDataAndType(uri, "application/x-chm"); //打开chm文件
////推断文件名称是否是某种类型的后缀
private boolean check(final String name, final String[] extensions) {
for (String end : extensions) {
if (name.toLowerCase().endsWith(end)) {
return true;
}
}
return false;
}
/////////////设置类型
if (check(name, ".apk")){
file.setType(FILE_TYPE_APK);
} else if(check(name, ".pdf")){
file.setType(FILE_TYPE_PDF);
} else if(check(name,
getStringArray(R.array.ppt_filter))){
file.setType(FILE_TYPE_PPT);
}
...................
array.ppt_filter:
<array name="ppt_filter">
<item>.ppt</item>
<item>.pptx</item>
</array>
//依据包名卸载apk
private void uninstallPkg(String pkg) {
Uri packageURI = Uri.parse("package:"+pkg);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
//也能够用这样的方法卸载
// getPackageManager().deletePackage(pkg, null, 0);
}
//获取设备存储路径(sd卡,usb)
Environment.getExternalStorageDirectory();
Environment.getExternalStorageDirectory().getParent();
笔记-Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)的更多相关文章
- 微信小程序云开发-云存储-下载并打开文件文件(word/excel/ppt/pdf)
一.wxml文件 1.写文本框,用来获取文件链接. 2.按钮,点击下载文件 <!-- 下载文件(word/excel/ppt/pdf等) --> <view class=" ...
- 微信小程序云开发-云存储-上传文件(word/excel/ppt/pdf)到云存储
说明 word/excel/ppt/pdf是从客户端会话选择文件.使用chooseMessageFile中选择文件. 一.wxml文件 上传按钮,绑定chooseFile <!--上传文件(wo ...
- 微信小程序云开发-云存储-上传、下载、打开文件文件(word/excel/ppt/pdf)一步到位
一.wxml文件 <!-- 上传.下载.打开文件一步执行 --> <view class="handle"> <button bindtap=&quo ...
- ASP.NET Core2集成Office Online Server(OWAS)实现办公文档的在线预览与编辑(支持word\excel\ppt\pdf等格式)
Office Online Server是微软开发的一套基于Office实现在线文档预览编辑的技术框架(支持当前主流的浏览器,且浏览器上无需安装任何插件,支持word.excel.ppt.pdf等文档 ...
- [转发]ASP.NET Core2集成Office Online Server(OWAS)实现办公文档的在线预览与编辑(支持word\excel\ppt\pdf等格式)
转载自:https://www.cnblogs.com/Andre/p/9549874.html Office Online Server是微软开发的一套基于Office实现在线文档预览编辑的技术框架 ...
- Android笔记——Android中数据的存储方式(二)
我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...
- Android中解析XML格式数据的方法
XML介绍:Extensible Markup Language,即可扩展标记语言 一.概述 Android中解析XML格式数据大致有三种方法: SAX DOM PULL 二.详解 2.1 SAX S ...
- excel打开csv格式的文件,数字末尾都变成零,解决方式
excel打开csv格式的文件,数字末尾都变成零,解决方式
- 第五十六篇、OC打开本地和网络上的word、ppt、excel、text等文件
iOS打开本地和网络上的word.ppt.excel.text等文件 iOS开发过程中可能需要预览一些文件,这些文件的格式可能有word.ppt.excel等文件格式.那么系统提供两个类去预览这些文件 ...
随机推荐
- [PHP] 2018年终总结
去掉敏感信息后的不完整版 ==========================================================================2018年12月29日 记 ...
- canvas-8searchLight3.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#基础(203)实例方法和重载方法总结,构造方法与实例方法总结,this关键字
c#方法的重载:分为实例方法重载和静态方法重载俩种 1.实例方法重载的调用特点 首先写三个Add方法和三个Sub方法 public int Add(int a,int b) { return a + ...
- Android项目实战(五十一):浅谈GreenDao
比较出名的数据库框架 GreenDao使用步骤: 1.app目录下的build.gradle文件 添加依赖 compile 'org.greenrobot:greendao:3.2.0' 顶部添加插件 ...
- Xamarin.Forms 使用本地数据库之 SQLite
前言 Xamarin.Forms支持使用SQLite数据库引擎.本文介绍了Xamarin.Forms应用程序如何读取和写入数据到使用SQLite.Net的本地SQLite数据库. 在Xamarin.F ...
- Spring整合ActiveMq消息队列
ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久 ...
- Linux 中如何避免 rm -rf /*
Linux 的删除命令中 rm中没有回收站的概念,一旦文件被删除比较难还原.更可怕的是rm -rf /*,连自己都能删 这命令太危险了,弄错了就核爆了,带来的损失的巨大的.比如 Gitlab.com ...
- 编写寄宿于windows服务的WCF服务
由于业务中有些任务需要在后台静默长期运行,或者有些服务队响应的要求比较苛刻,这样的WCF服务就不适合寄宿于IIS中.IIS每隔一段时间w3wp进程会闲置超时,造成服务的运行停止,因此这种耗时或者定时任 ...
- linux(centos)无中文输入,如何解决
1.终端执行安装命令 yum install "@Chinese Support" 2.如下图,多出Input method 3.点击进行配置 4.reboot重启系统,新建一个文 ...
- AWS云使用100条宝贵经验分享
在今天的文章中,我整理出了大量当初曾经错过.而至今仍将我追悔莫及的Amazon Web Services(简称AWS)使用心得.在几年来的实践当中,我通过在AWS之上新手构建及部署各类应用程序而积累到 ...