android打开pdf ppt word excel chm html text 文件的intent

简介:
以下代码未经测试。但是有我想找的,先贴过来,慢慢了解~~ 

import android.app.Activity; 

import android.content.Intent; 

import android.net.Uri; 

import android.net.Uri.Builder; 

import java.io.File; 

import android.content.Intent; 



//自定义android Intent类, 

//可用于获取打开以下文件的intent 

//PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO 

public class MyIntent 

{ 



//android获取一个用于打开HTML文件的intent 

  public static Intent getHtmlFileIntent( String param ) 

  { 

  Uri uri = Uri.parse(param ).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme("content").encodedPath(param ).build(); 

  Intent intent = new Intent("android.intent.action.VIEW"); 

  intent.setDataAndType(uri, "text/html"); 

  return intent; 

  } 



//android获取一个用于打开图片文件的intent 

  public static Intent getImageFileIntent( String param ) 

  { 

  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(new File(param )); 

  intent.setDataAndType(uri, "image/*"); 

  return intent; 

  } 



  //android获取一个用于打开PDF文件的intent 

  public static Intent getPdfFileIntent( String param ) 

  { 

  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(new File(param )); 

  intent.setDataAndType(uri, "application/pdf"); 

  return intent; 

  } 



//android获取一个用于打开文本文件的intent 

  public static Intent getTextFileIntent( String paramString, boolean paramBoolean) 

  { 

  Intent intent = new Intent("android.intent.action.VIEW"); 

  intent.addCategory("android.intent.category.DEFAULT"); 

  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

  if (paramBoolean) 

  { 

  Uri uri1 = Uri.parse(param ); 

  intent.setDataAndType(uri1, "text/plain"); 

  } 

  while (true) 

  { 

  return intent; 

  Uri uri2 = Uri.fromFile(new File(param )); 

  intent.setDataAndType(uri2, "text/plain"); 

  } 

  } 











//android获取一个用于打开音频文件的intent 

  public static Intent getAudioFileIntent( String param ) 

  { 

  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(new File(param )); 

  intent.setDataAndType(uri, "audio/*"); 

  return intent; 

  } 







  //android获取一个用于打开视频文件的intent 

  public static Intent getVideoFileIntent( String param ) 

  { 

  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(new File(param )); 

  intent.setDataAndType(uri, "video/*"); 

  return intent; 

  } 





  //android获取一个用于打开CHM文件的intent 

  public static Intent getChmFileIntent( String param ) 

  { 

  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(new File(param )); 

  intent.setDataAndType(uri, "application/x-chm"); 

  return intent; 

  } 







//android获取一个用于打开Word文件的intent 

  public static Intent getWordFileIntent( String param ) 

  { 

  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(new File(param )); 

  intent.setDataAndType(uri, "application/msword"); 

  return intent; 

  } 



//android获取一个用于打开Excel文件的intent 

  public static Intent getExcelFileIntent( String param ) 

  { 

  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(new File(param )); 

  intent.setDataAndType(uri, "application/vnd.ms-excel"); 

  return intent; 

  } 

  

  

//android获取一个用于打开PPT文件的intent 

  public static Intent getPptFileIntent( String param ) 

  { 

  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(new File(param )); 

  intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); 

  return intent; 

  } 



} 

相关文章
|
18天前
|
小程序
公众号如何添加附传Word、Excel、Pdf、PPT文档
公众号里添加一些文档给公众号粉丝下载,比如课件PPT、申请表Word文档、岗位需求Excel表、大赛入围/获奖名单等。公众号本身是不支持直接上传文件的,但我们可以通过附件小程序“间接”上传文件。
200 0
|
3月前
|
安全 数据库 Android开发
在Android开发中实现两个Intent跳转及数据交换的方法
总结上述内容,在Android开发中,Intent不仅是活动跳转的桥梁,也是两个活动之间进行数据交换的媒介。运用Intent传递数据时需注意数据类型、传输大小限制以及安全性问题的处理,以确保应用的健壯性和安全性。
179 11
|
3月前
|
Python
Excel中如何批量重命名工作表与将每个工作表导出到单独Excel文件
本文介绍了如何在Excel中使用VBA批量重命名工作表、根据单元格内容修改颜色,以及将工作表导出为独立文件的方法。同时提供了Python实现导出工作表的代码示例,适用于自动化处理Excel文档。
|
5月前
|
人工智能 算法 安全
使用CodeBuddy实现批量转换PPT、Excel、Word为PDF文件工具
通过 CodeBuddy 实现本地批量转换工具,让复杂的文档处理需求转化为 “需求描述→代码生成→一键运行” 的极简流程,真正实现 “技术为效率服务” 的目标。感兴趣的快来体验下把
166 10
|
6月前
|
安全 搜索推荐 iOS开发
WPS Office for Mac 7.3.1 - 写作、表格处理、PPT 制作和 PDF 编辑
WPS Office for Mac 7.3.1 - 写作、表格处理、PPT 制作和 PDF 编辑
273 8
WPS Office for Mac 7.3.1 - 写作、表格处理、PPT 制作和 PDF 编辑
|
10月前
|
人工智能 自然语言处理 Java
FastExcel:开源的 JAVA 解析 Excel 工具,集成 AI 通过自然语言处理 Excel 文件,完全兼容 EasyExcel
FastExcel 是一款基于 Java 的高性能 Excel 处理工具,专注于优化大规模数据处理,提供简洁易用的 API 和流式操作能力,支持从 EasyExcel 无缝迁移。
1983 65
FastExcel:开源的 JAVA 解析 Excel 工具,集成 AI 通过自然语言处理 Excel 文件,完全兼容 EasyExcel
|
8月前
|
文字识别 Serverless 开发工具
【全自动改PDF名】批量OCR识别提取PDF自定义指定区域内容保存到 Excel 以及根据PDF文件内容的标题来批量重命名
学校和教育机构常需处理成绩单、报名表等PDF文件。通过OCR技术,可自动提取学生信息并录入Excel,便于统计分析和存档管理。本文介绍使用阿里云服务实现批量OCR识别、内容提取、重命名及导出表格的完整步骤,包括开通相关服务、编写代码、部署函数计算和设置自动化触发器等。提供Python示例代码和详细操作指南,帮助用户高效处理PDF文件。 链接: - 百度网盘:[链接](https://pan.baidu.com/s/1mWsg7mDZq2pZ8xdKzdn5Hg?pwd=8866) - 腾讯网盘:[链接](https://share.weiyun.com/a77jklXK)
836 5
|
8月前
|
文字识别 BI
【图片型PDF】批量识别扫描件PDF指定区域局部位置内容,将识别内容导出Excel表格或批量改名文件,基于阿里云OCR对图片型PDF识别改名案例实现
在医疗和政务等领域,图片型PDF文件(如病历、报告、公文扫描件)的处理需求广泛。通过OCR技术识别这些文件中的文字信息,提取关键内容并保存为表格,极大提高了信息管理和利用效率。本文介绍一款工具——咕嘎批量OCR系统,帮助用户快速处理图片型PDF文件,支持区域识别、内容提取、导出表格及批量改名等功能。下载工具后,按步骤选择处理模式、进行区域采样、批量处理文件,几分钟内即可高效完成数百个文件的处理。
818 8
|
10月前
|
人工智能 自然语言处理 JavaScript
Univer:开源全栈 AI 办公工具,支持 Word、Excel、PPT 等文档处理和多人实时协作
Univer 是一款开源的 AI 办公工具,支持 Word、Excel 等文档处理的全栈解决方案。它具有强大的功能、高度的可扩展性和跨平台兼容性,适用于个人和企业用户,能够显著提高工作效率。
1403 9
Univer:开源全栈 AI 办公工具,支持 Word、Excel、PPT 等文档处理和多人实时协作
|
3月前
|
Python
如何根据Excel某列数据为依据分成一个新的工作表
在处理Excel数据时,我们常需要根据列值将数据分到不同的工作表或文件中。本文通过Python和VBA两种方法实现该操作:使用Python的`pandas`库按年级拆分为多个文件,再通过VBA宏按班级生成新的工作表,帮助高效整理复杂数据。

热门文章

最新文章