`

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获取一个用于打开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获取一个用于打开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获取一个用于打开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获取一个用于打开文本文件的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获取一个用于打开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

    android用于打开各种文件的intent

    Android中调用系统所装的软件打开文件

    * 打开文件 * @param file */ private void openFile(File file){ Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //设置intent的Action属性 intent.setAction...

    一个Android文件下载Download程序示例

    一个Android文件下载Download程序...调用getMIMEType()来取得MimeType,设置intent的file与MimeType ,判断文件MimeType的method,取得扩展名,依扩展名的类型决定MimeType,如果无法直接打开,就跳出软件列表给用户选择.

    Android FileMan文件扫描管理记录使用次数.rar

    一个Android文件管理器APP源码,类似于360手机助手的功能,可以记录文件使用次数,... 本SD卡扫描程序还自定义了android Intent类,可用于获取打开以下文件的intent:PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO。

    react-native-file-viewer:React Native的本机文件查看器。 预览移动设备支持的任何类型的文件

    预览移动设备支持的任何类型的文件。 iOS :它使用 Android :它使用ACTION_VIEW Intent启动与指定文件关联的默认应用。 Windows :启动与指定文件关联的默认应用程序。 入门 $ npm install react-native-file-...

    Android判断和读取图标列表iconFile实例

    ,调用getMIMEType()来取得MimeType,设置intent的file与MimeType ,判断文件MimeType的方法,如果无法直接打开,就跳出软件列表给用户选择。变量声明:items:存放显示的名称,paths:存放文件路径,rootPath:起始...

    Android开发资料合集--续

    打开多种类型的文件: 21 Uninstall 程序 24 14、将Uri转为绝对路径 24 15、Android支持多种语言 25 16、四种动画的设置属性 25 1、尺寸伸缩动画效果 25 2、translate 位置转移动画效果 27 3、rotate 旋转动画效果 ...

    新版Android开发教程.rar

    ----------------------------------- Android 编程基础 1 封面----------------------------------- Android 编程基础 2 开放手机联盟 --Open --Open --Open --Open Handset Handset Handset Handset Alliance ...

    开发多媒体播放器

    //如果是媒体文件直接打开播放 openFile(pathEditText.getText().toString()); } else { //如果是目录打开目录下文件 getFileDir(pathEditText.getText().toString()); } } ...

    Google Android SDK开发范例大全(PDF高清完整版3)(4-3)

    8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...

    Google Android SDK开发范例大全(PDF完整版4)(4-4)

    8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...

    Google Android SDK开发范例大全(PDF高清完整版1)(4-1)

    8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...

    redirectToNative:移动端上native类型(ios or andriod)判断和native是否安装判断的常用跳转逻辑

    ]修复Android下打开客户端的同时下载apk文件,ios和android打开客户端的时间有差异,提供配置项 [!]测试发现魅族手机下的无法识别app注册的协议(如etao://item),可通过降级引导用户操作。 V1.1 [!]提供基础的js...

    Google Android SDK开发范例大全的目录

    8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...

    Google+Android+SDK开发范例大全

    8.2 在程序里浏览网页——WebView.loadUrl 8.3 嵌入HTML标记的程序——WebView.loadData 8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter ...

    Google Android SDK开发范例大全(完整版附部分源码).pdf

    8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...

    Google Android sdk 开发范例大全 部分章节代码

    8.4 设计前往打开网页功能——Intent与Uri.parse 8.5 将网络图像网址放入Gallery中显示——URL.URLConnection.BaseAdapter 8.6 即时访问网络图文件展示——HttpURLConnection 8.7 手机气象局,实时卫星云图——...

Global site tag (gtag.js) - Google Analytics