Android中调用第三方打开本地doc、pdf、ppt、text等文件功能的实现

2024-05-09 14:58

本文主要是介绍Android中调用第三方打开本地doc、pdf、ppt、text等文件功能的实现,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

打开各种格式文件的工具类,代码如下

import android.content.Intent;  
import android.net.Uri;  import java.io.File;  public class FileUtils {  //android获取一个用于打开HTML文件的intent  public static Intent getHtmlFileIntent(String Path)  {  File file = new File(Path);  Uri uri = Uri.parse(file.toString()).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme("content").encodedPath(file.toString()).build();  Intent intent = new Intent("android.intent.action.VIEW");  intent.setDataAndType(uri, "text/html");  return intent;  }  //android获取一个用于打开图片文件的intent  public static Intent getImageFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent("android.intent.action.VIEW");  intent.addCategory("android.intent.category.DEFAULT");  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  Uri uri = Uri.fromFile(file);  intent.setDataAndType(uri, "image/*");  return intent;  }  //android获取一个用于打开PDF文件的intent  public static Intent getPdfFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent("android.intent.action.VIEW");  intent.addCategory("android.intent.category.DEFAULT");  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  Uri uri = Uri.fromFile(file);  intent.setDataAndType(uri, "application/pdf");  return intent;  }  //android获取一个用于打开文本文件的intent  public static Intent getTextFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent("android.intent.action.VIEW");  intent.addCategory("android.intent.category.DEFAULT");  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  Uri uri = Uri.fromFile(file);  intent.setDataAndType(uri, "text/plain");  return intent;  }  //android获取一个用于打开音频文件的intent  public static Intent getAudioFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent("android.intent.action.VIEW");  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  intent.putExtra("oneshot", 0);  intent.putExtra("configchange", 0);  Uri uri = Uri.fromFile(file);  intent.setDataAndType(uri, "audio/*");  return intent;  }  //android获取一个用于打开视频文件的intent  public static Intent getVideoFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent("android.intent.action.VIEW");  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  intent.putExtra("oneshot", 0);  intent.putExtra("configchange", 0);  Uri uri = Uri.fromFile(file);  intent.setDataAndType(uri, "video/*");  return intent;  }  //android获取一个用于打开CHM文件的intent  public static Intent getChmFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent("android.intent.action.VIEW");  intent.addCategory("android.intent.category.DEFAULT");  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  Uri uri = Uri.fromFile(file);  intent.setDataAndType(uri, "application/x-chm");  return intent;  }  //android获取一个用于打开Word文件的intent  public static Intent getWordFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent("android.intent.action.VIEW");  intent.addCategory("android.intent.category.DEFAULT");  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  Uri uri = Uri.fromFile(file);  intent.setDataAndType(uri, "application/msword");  return intent;  }  //android获取一个用于打开Excel文件的intent  public static Intent getExcelFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent("android.intent.action.VIEW");  intent.addCategory("android.intent.category.DEFAULT");  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  Uri uri = Uri.fromFile(file);  intent.setDataAndType(uri, "application/vnd.ms-excel");  return intent;  }  //android获取一个用于打开PPT文件的intent  public static Intent getPPTFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent("android.intent.action.VIEW");  intent.addCategory("android.intent.category.DEFAULT");  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  Uri uri = Uri.fromFile(file);  intent.setDataAndType(uri, "application/vnd.ms-powerpoint");  return intent;  }  //android获取一个用于打开apk文件的intent  public static Intent getApkFileIntent(String Path)  {  File file = new File(Path);  Intent intent = new Intent();  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  intent.setAction(android.content.Intent.ACTION_VIEW);  intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");  return intent;  }  
}  

转自:http://blog.csdn.net/baidu_34260638/article/details/53120737

这篇关于Android中调用第三方打开本地doc、pdf、ppt、text等文件功能的实现的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/973706

相关文章

关于集合与数组转换实现方法

《关于集合与数组转换实现方法》:本文主要介绍关于集合与数组转换实现方法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、Arrays.asList()1.1、方法作用1.2、内部实现1.3、修改元素的影响1.4、注意事项2、list.toArray()2.1、方

使用Python实现可恢复式多线程下载器

《使用Python实现可恢复式多线程下载器》在数字时代,大文件下载已成为日常操作,本文将手把手教你用Python打造专业级下载器,实现断点续传,多线程加速,速度限制等功能,感兴趣的小伙伴可以了解下... 目录一、智能续传:从崩溃边缘抢救进度二、多线程加速:榨干网络带宽三、速度控制:做网络的好邻居四、终端交互

mysql表操作与查询功能详解

《mysql表操作与查询功能详解》本文系统讲解MySQL表操作与查询,涵盖创建、修改、复制表语法,基本查询结构及WHERE、GROUPBY等子句,本文结合实例代码给大家介绍的非常详细,感兴趣的朋友跟随... 目录01.表的操作1.1表操作概览1.2创建表1.3修改表1.4复制表02.基本查询操作2.1 SE

java实现docker镜像上传到harbor仓库的方式

《java实现docker镜像上传到harbor仓库的方式》:本文主要介绍java实现docker镜像上传到harbor仓库的方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录1. 前 言2. 编写工具类2.1 引入依赖包2.2 使用当前服务器的docker环境推送镜像2.2

C++20管道运算符的实现示例

《C++20管道运算符的实现示例》本文简要介绍C++20管道运算符的使用与实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录标准库的管道运算符使用自己实现类似的管道运算符我们不打算介绍太多,因为它实际属于c++20最为重要的

一文详解Git中分支本地和远程删除的方法

《一文详解Git中分支本地和远程删除的方法》在使用Git进行版本控制的过程中,我们会创建多个分支来进行不同功能的开发,这就容易涉及到如何正确地删除本地分支和远程分支,下面我们就来看看相关的实现方法吧... 目录技术背景实现步骤删除本地分支删除远程www.chinasem.cn分支同步删除信息到其他机器示例步骤

Java easyExcel实现导入多sheet的Excel

《JavaeasyExcel实现导入多sheet的Excel》这篇文章主要为大家详细介绍了如何使用JavaeasyExcel实现导入多sheet的Excel,文中的示例代码讲解详细,感兴趣的小伙伴可... 目录1.官网2.Excel样式3.代码1.官网easyExcel官网2.Excel样式3.代码

Java中调用数据库存储过程的示例代码

《Java中调用数据库存储过程的示例代码》本文介绍Java通过JDBC调用数据库存储过程的方法,涵盖参数类型、执行步骤及数据库差异,需注意异常处理与资源管理,以优化性能并实现复杂业务逻辑,感兴趣的朋友... 目录一、存储过程概述二、Java调用存储过程的基本javascript步骤三、Java调用存储过程示

python实现对数据公钥加密与私钥解密

《python实现对数据公钥加密与私钥解密》这篇文章主要为大家详细介绍了如何使用python实现对数据公钥加密与私钥解密,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录公钥私钥的生成使用公钥加密使用私钥解密公钥私钥的生成这一部分,使用python生成公钥与私钥,然后保存在两个文

浏览器插件cursor实现自动注册、续杯的详细过程

《浏览器插件cursor实现自动注册、续杯的详细过程》Cursor简易注册助手脚本通过自动化邮箱填写和验证码获取流程,大大简化了Cursor的注册过程,它不仅提高了注册效率,还通过友好的用户界面和详细... 目录前言功能概述使用方法安装脚本使用流程邮箱输入页面验证码页面实战演示技术实现核心功能实现1. 随机