我们有时候遇到要打开一个文件,我们可以选择用其他应用打开,这时弹出来的应用列表,那么我们如何让自己开发的应用也能出现在里面呢?

第一步:设置启动Activity的intent-filter,给data 指定可以打开的mimeType.(注意允许文件操作的权限)

 <activity
android:name=".StartActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
</activity>

mimeType的值,我们可以根据需要设置对应的文件类型

文件类型 mimeType
.pdf application/pdf
.jpg image/jpeg
.txt text/plain
.apk application/vnd.android.package-archive
所有文件 */*

第二步:在我们设置接受的Activity 中获取文件的Uri

//StartActivity  
Intent intent=getIntent();
if (intent!=null) {
Uri uriFileShare = intent.getData();
if(uriFileShare!=null){
String filePath= uriFileShare.getPath();
}
}

如此我们便能获取到打开文件的路径,接下来就能自己操作该文件了。

Android应用打开外部文件的更多相关文章

  1. MFC 用ShellExecute打开外部文件

    知识点: 获取CListCtrl选中文本 用ShellExecute打开外部文件 一.CListCtrl::GetFirstSelectedItemPosition CListCtrl::GetFir ...

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

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

  3. 【Android】把外部文件拷贝的AVD安卓模拟器上的sdcard上,而且在AVD中浏览sdcard的文件

    首先.实现这一切的大前提是.你的AVD安卓模拟器,在启动之前.有设置好sdcard的大小,例如以下图.同一时候,你的AVD安卓模拟器,要处于启动状态.否则无法运行例如以下的操作. 这里以<[An ...

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

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

  5. android用于打开各种文件的intent

    import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.n ...

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

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

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

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

  8. Android打开外部DB文件

    DB文件要放在Assets文件夹下,封装一个工具类,如下: package com.XX.DB; import java.io.File; import java.io.FileOutputStrea ...

  9. 【Android】14.2 外部文件存储和读取

    分类:C#.Android.VS2015: 创建日期:2016-02-27 一.简介 1.基本概念 内部存储的私有可用存储空间一般都不会很大,对于容量比较大的文件,例如视频等,应该将其存储在外部存储设 ...

随机推荐

  1. ubuntu安装gcc不同的版本

    服务器ubuntu14.04安装ns3.29中,显示gcc版本过低 使用apt-get安装失败,ubuntu14.04默认安装gcc4.8.4,无法下载更高级的gcc版本 先找到资料1,脚本尝试了,下 ...

  2. webpack + typescript + babel打包*.min.js文件的环境配置

    将多个*.ts文件打包成一个*.min.js文件的开发配置 1.初始化 npm init 新建以下文件目录: 2.安装依赖: "devDependencies": { " ...

  3. 关于angularjs异步操作后台请求时,用$q.all排列先后顺序的问题

    最近我在做angularjs程序时遇到了一个问题 1.页面有很多选择框,一个选择框里面有众多的选择项,和一个默认选定的项,像下面这样(很多选择框,不只一个): 2.众多的选项要从后台接口得到,默认项从 ...

  4. 默认VS 下machine.config的位置

  5. hadoop节点动态删除与增加

    动态删除 1)修改配置文件 修改hdfs-site.xml文件,适当减小dfs.replication的数量,增加dfs.hosts.exclude选项 vi hdfs-site.xml <pr ...

  6. Attaching an entity of type 'xxx' failed because another entity of the same type already has the same primary key value.

    问题的详细描述: Attaching an entity of type 'xxxxx' failed because another entity of the same type already ...

  7. Octave中的矩阵常用操作2

    sum(a):矩阵里的数据求和prod(a):乘积floor(a):向上取整ceil(a):向下取整max(A,[],1):取每一列的最大值max(A,[],2):取每一行的最大值max(max(A) ...

  8. java8接口

    // 可以用来做工具类// 这个注解是函数式注解,表示这个接口里面有且仅有一个抽象方法, 默认方法可以有0个或多个@FunctionalInterfacepublic interface Interf ...

  9. f.lux

    这软件很小,安装后基本不用管,它会自动运行自动调节.在它运行的时候,一般在桌面右小角可以找到.平时不用去管它,它自会按时自动调节好屏幕的色温,以保护视力. https://justgetflux.co ...

  10. LVS负载均衡实现双向热备

    一.LVS1服务器配置 安装ipvsadm,keepalived [root@localhost ~]# yum -y install ipvsadm keepalived 配置keepalivedd ...