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

示例:

//这个不行,可能是因为PDF.apk程序没有权限访问其它APK里的asset资源文件,又或者是路径写错?

//Intent it = getPdfFileIntent("file:///android_asset/helphelp.pdf");

//下面这些都OK

//Intent it = getHtmlFileIntent("/mnt/sdcard/tutorial.html");//SD卡主目录

//Intent it = getHtmlFileIntent("/sdcard/tutorial.html");//SD卡主目录,这样也可以

Intent it = getHtmlFileIntent("/system/etc/tutorial.html");//系统内部的etc目录

//Intent it = getPdfFileIntent("/system/etc/helphelp.pdf");

//Intent it = getWordFileIntent("/system/etc/help.doc");

//Intent it = getExcelFileIntent("/mnt/sdcard/Book1.xls")

//Intent it = getPptFileIntent("/mnt/sdcard/download/Android_PPT.ppt");//SD卡的download目录下

//Intent it = getVideoFileIntent("/mnt/sdcard/ice.avi");

//Intent it = getAudioFileIntent("/mnt/sdcard/ren.mp3");

//Intent it = getImageFileIntent("/mnt/sdcard/images/001041580.jpg");

//Intent it = getTextFileIntent("/mnt/sdcard/hello.txt",false);

startActivity( it );

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 param, 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");

}

else

{

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

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

}

return intent;

}

//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;

}

}

android用于打开各种文件的intent的更多相关文章

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

    近期在做项目使用webview显示后,有写文档须要打开,找了一些资料,研究了一下,弄出来了! 以下贴一下主要代码: param为文档的主要路径 public static Intent getWord ...

  2. Android(java)学习笔记143:android提供打开各种文件的API接口:setDataAndType

    android 打开各种文件(setDataAndType) private void openFile(File file){ Intent intent = new Intent(); inten ...

  3. Android(java)学习笔记86:Android提供打开各种文件的API接口:setDataAndType

    1. Android 打开各种文件(setDataAndType) private void openFile(File file){ Intent intent = new Intent(); in ...

  4. Android应用打开外部文件

    我们有时候遇到要打开一个文件,我们可以选择用其他应用打开,这时弹出来的应用列表,那么我们如何让自己开发的应用也能出现在里面呢? 第一步:设置启动Activity的intent-filter,给data ...

  5. Android使用文件管理器打开指定文件夹,浏览里面的内容

    Android下可以打开一些文件,带有.doc 等后缀的文件网上一般都有解释,这个写一个使用文件管理器打开指定文件夹的 private void openAssignFolder(String pat ...

  6. 二十一、utl_file(用于读写OS文件)

    1.概述 作用:用于读写OS文件.使用该包访问OS文件时,必须要为OS目录建立相应的DIRECTORY对象..当用户要访问特定目录下的文件时,必须要具有读写DIRECTORY对象的权限.在使用UTL_ ...

  7. android intent打开各种文件的方法

    android intent打开各种文件的方法   1./**  * 检测是否安装了某个软件  *   * @param pkgName "com.bill99.kuaishua" ...

  8. android 打开各种文件(setDataAndType)转:

    android 打开各种文件(setDataAndType) 博客分类: android-->非界面 android 打开各种文件 setDataAndType action动作  转自:htt ...

  9. 笔记-Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)

    打开后缀.apk的文件.即启动安装程序. //apkFilePath 文件路径 public void installAPK(String apkFilePath) { // 创建URI Uri ur ...

随机推荐

  1. linux shell编程指南第十一章------------合并与分割2

    c u t用来从标准输入或文本文件中剪切列或域.剪切文本可以将之粘贴到一个文本文件. 下一节将介绍粘贴用法. c u t一般格式为: cut [options] file1 file2 下面介绍其可用 ...

  2. [放松一下] 经典高清电影合集 170G BT种子下载

    经典高清电影合集 170G BT种子下载 点击文件名下载 经典高清电影合集170G BT种子.torrent 下载方法 经典高清电影合集详情见目录: 1. 杀手47 2. 这个杀手不太冷 3. 放牛班 ...

  3. CSS——float属性备忘笔记

    通过指定CSS属性float的值,从而使元素向左或向右浮动,然后由后继元素向上移动以填补前面元素的浮动而空出的可用空间.CSS的float属性,作用就是改变块元素对象的默认显示方式,HTML标签设置了 ...

  4. node-inspector使用

    nodejs.gulp调试工具node-inspector使用 俗话说欲善其功,必先利其器. 作为目前新型的Web Server开发栈倍受开发者关注的Nodejs来说,调试技术是学习开发的基石,所以对 ...

  5. Delphi 10.1说明

    发布说明:http://docwiki.embarcadero.com/RADStudio/Berlin/en/Main_Page更新说明:http://docwiki.embarcadero.com ...

  6. webdynpro的select_option示例

    需求,输入航线代码和航线编号区间,查询记录存在表中显示,并不是alv显示 1.使用组件WDR_SELECT_OPTIONS. 2.在组件控制器中加入以下组件 3.在视图属性中也添加该组件 4.创建节点 ...

  7. Mybatis 数据库物理分页插件 PageHelper

    以前使用ibatis/mybatis,都是自己手写sql语句进行物理分页,虽然稍微有点麻烦,但是都习惯了.最近试用了下mybatis的分页插件 PageHelper,感觉还不错吧.记录下其使用方法. ...

  8. 阻塞队列BlockingQueue用法(转)

    多线程环境中,通过队列可以很容易实现数据共享,比如经典的“生产者”和“消费者”模型中,通过队列可以很便利地实现两者之间的数据共享. 假设我们有若干生产者线程,另外又有若干个消费者线程.如果生产者线程需 ...

  9. WinExec函数,启动其他应用程序

    WinExec The WinExec function runs the specified application. Note  This function is provided only fo ...

  10. Android菜鸟的成长笔记(12)——Handler、Loop、MessageQueue

    原文:[置顶] Android菜鸟的成长笔记(12)——Handler.Loop.MessageQueue 当一个程序第一次启动时,Android会启动一条主线程(Main Thread),主线程主要 ...