例如:

1.想实现其他应用打开出现自己的应用,需要在清单文件中增加配置

注:自己需要什么样的文件格式自己可以配置,其中 minType 代表要打开的文件类型。

常用的类型:

{".3gp", "video/3gpp"},

{".apk", "application/vnd.android.package-archive"},

{".asf", "video/x-ms-asf"},

{".avi", "video/x-msvideo"},

{".bin", "application/octet-stream"},

{".bmp", "image/bmp"},

{".c", "text/plain"},

{".class", "application/octet-stream"},

{".conf", "text/plain"},

{".cpp", "text/plain"},

{".doc", "application/msword"},

{".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},

{".xls", "application/vnd.ms-excel"},

{".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},

{".exe", "application/octet-stream"},

{".gif", "image/gif"},

{".gtar", "application/x-gtar"},

{".gz", "application/x-gzip"},

{".h", "text/plain"},

{".htm", "text/html"},

{".html", "text/html"},

{".jar", "application/java-archive"},

{".java", "text/plain"},

{".jpeg", "image/jpeg"},

{".jpg", "image/jpeg"},

{".js", "application/x-javascript"},

{".log", "text/plain"},

{".m3u", "audio/x-mpegurl"},

{".m4a", "audio/mp4a-latm"},

{".m4b", "audio/mp4a-latm"},

{".m4p", "audio/mp4a-latm"},

{".m4u", "video/vnd.mpegurl"},

{".m4v", "video/x-m4v"},

{".mov", "video/quicktime"},

{".mp2", "audio/x-mpeg"},

{".mp3", "audio/x-mpeg"},

{".mp4", "video/mp4"},

{".mpc", "application/vnd.mpohun.certificate"},

{".mpe", "video/mpeg"},

{".mpeg", "video/mpeg"},

{".mpg", "video/mpeg"},

{".mpg4", "video/mp4"},

{".mpga", "audio/mpeg"},

{".msg", "application/vnd.ms-outlook"},

{".ogg", "audio/ogg"},

{".pdf", "application/pdf"},

{".png", "image/png"},

{".pps", "application/vnd.ms-powerpoint"},

{".ppt", "application/vnd.ms-powerpoint"},

{".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"},

{".prop", "text/plain"},

{".rc", "text/plain"},

{".rmvb", "audio/x-pn-realaudio"},

{".rtf", "application/rtf"},

{".sh", "text/plain"},

{".tar", "application/x-tar"},

{".tgz", "application/x-compressed"},

{".txt", "text/plain"},

{".wav", "audio/x-wav"},

{".wma", "audio/x-ms-wma"},

{".wmv", "audio/x-ms-wmv"},

{".wps", "application/vnd.ms-works"},

{".xml", "text/plain"},

{".z", "application/x-compress"},

{".zip", "application/x-zip-compressed"},

{"", "*/*"}

2.获取到文件路径

if (intent.ACTION_VIEW.equals(action)) {

Uri uri = intent.getData();

String str = Uri.decode(uri.getEncodedPath());

//获取到真实路径 GetRealPath.getFPUriToPath()

String path="file://" + GetRealPath.getFPUriToPath(this, uri)}

2.1 获取真实路径 GetRealPath.getFPUriToPath()方法:

public class GetRealPath {

public static String getFPUriToPath(Context context, Uri uri) {

try {

Listpacks = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);

if (packs != null) {

String fileProviderClassName = FileProvider.class.getName();

for (PackageInfo pack : packs) {

ProviderInfo[] providers = pack.providers;

if (providers != null) {

for (ProviderInfo provider : providers) {

if (uri.getAuthority().equals(provider.authority)) {

if (provider.name.equalsIgnoreCase(fileProviderClassName)) {

ClassfileProviderClass = FileProvider.class;

try {

Method getPathStrategy = fileProviderClass.getDeclaredMethod("getPathStrategy", Context.class, String.class);

getPathStrategy.setAccessible(true);

Object invoke = getPathStrategy.invoke(null, context, uri.getAuthority());

if (invoke != null) {

String PathStrategyStringClass = FileProvider.class.getName() + "$PathStrategy";

Class> PathStrategy = Class.forName(PathStrategyStringClass);

Method getFileForUri = PathStrategy.getDeclaredMethod("getFileForUri", Uri.class);

getFileForUri.setAccessible(true);

Object invoke1 = getFileForUri.invoke(invoke, uri);

if (invoke1 instanceof File) {

String filePath = ((File) invoke1).getAbsolutePath();

return replace(filePath);

}

}

} catch (NoSuchMethodException e) {

e.printStackTrace();

} catch (InvocationTargetException e) {

e.printStackTrace();

} catch (IllegalAccessException e) {

e.printStackTrace();

} catch (ClassNotFoundException e) {

e.printStackTrace();

}

break;

}

break;

}

}

}

}

}

} catch (Exception e) {

e.printStackTrace();

}

return null;

}

public static String replace(String filePath) {

if (filePath.contains("%")) {

filePath = filePath.replace("%", "%25");

}

if (filePath.contains("#")) {

filePath = filePath.replace("%", "%23");

}

if (filePath.contains("&")) {

filePath = filePath.replace("%", "%26");

}

if (filePath.contains("?")) {

filePath = filePath.replace("%", "%3F");

}

return filePath;

}

}

2.2获取真实路径.java:

GetRealPath.java

java android 读取微信文件,Android 实现微信,QQ文件在其他应用打开并获取到路径相关推荐

  1. android 读取excel数据并保存为xml文件

    今天,简单讲讲android如何  读取excel数据并保存为xml文件. 最近,我这边需要把客户翻译的Excel字符资源作为xml字符资源,当时自己是一个一个的复制,发现效率太低.后来,在网上搜 ...

  2. java excel转pdf linux,从JAVA直接读取EXCEL、WORD并生成PDF文件

    从JAVA直接读取EXCEL.WORD并生成PDF文件 1.操作EXCEL和WORD文件 使用JAVA从EXCEL.WORD文件中读写数据,可以使用http://jexcelapi.sourcefor ...

  3. android跳转到相册需要权限,Android打开相册获取图片路径

    一.获得图片路径 当我们通过Intent打开相册,获取图片后,在onActivityResult回调中会得到图片的Uri. 但是Uri无法直接获得图片的路径.如果你曾经直接操作过android里的数据 ...

  4. android读取外部图片,Android读取本地图库与调用摄像头拍摄

    本文主要介绍如何读取Android本地图库的图片以及调用安卓的摄像头进行拍摄. 一.布局 布局比较简单,MainActviivty的布局文件只有两个按钮,一个是读取图库的,另一个是打开摄像头的,另外R ...

  5. Android 调用系统打开相机,打开相册获取图片路径

    我们在开发中经常遇到一些功能需要调取系统相机拍照获取图片,或者有的时候直接打开图库获取图片,那我们怎么获取呢,今天分享下, 第一步,打开相机 public static final int CAMER ...

  6. windows11无法拖动文件的现象解决方案/QQ文件拖动方法

    日常生活经常搭配 虚拟机 所以需要 拖动文件操作(真香)常常出现失效问题那么如何解决? 原因:系统进程未完全退出 解决办法:多按两次ESC键,或者重启电脑(当然我一般不敢这样,还有很多未完成的任务) ...

  7. android读取xml 字符串,Android 读取本地Xml文件,并转换成String

    问题 不是解析本地 xml 文件, 而是要将 xml 文件中的所有内容(包含格式,标签等),直接转换成 String. 与前端H5页面交互时, iOS 在请求远程 xml 文件耗时太长(有时需要4~5 ...

  8. android 读取手机mp3,Android四大组件之ContentResolver读取手机音乐文件

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 //就像查询数据库 Cursor cursor = query(RI uri,String[]projection,String selection ,S ...

  9. android读取excel数据库,Android 读取Excel数据并保存在本地数据库

    在工作中遇到需要将Excel的数据读取出来并保存在本地数据库中的操作,数据如下: 图片.png 需要做以下准备: 读取Excel的jar包[文章末尾会分享该jar包] 保存数据的数据库框架,在这里我们 ...

最新文章

  1. Work with Alexa :Echo匹配连接到Alexa
  2. BM16 删除有序链表中重复的元素-II
  3. 利用Python进行数据分析(1) 简单介绍
  4. 阿里云周源:一篇文章读懂四代视频加密技术演进
  5. nginx location 匹配 多个规则_三道小练习助你弄懂 Nginx location 匹配
  6. 【FLink】cannot assign instance LinkedMap FlinkKafkaConsumerBase.pendingOffsetsToCommit
  7. Windows Azure系列公开课 - 第二课:为什么选择Windows Azure(下)
  8. linq to access 简单实现
  9. mysql 时间设置
  10. Ubuntu下安装osu
  11. 进销存系统设计说明书
  12. Vue PC端分辨率自适应
  13. ARPG游戏设计制作随笔
  14. STM32的USART串口通讯程序(查询方式)
  15. box2d的角色邹形
  16. EOS源码分析(5)账号
  17. 【SICP练习】95 练习2.68
  18. BMC-web的介绍(一)
  19. Python系列(五):bytes和str的区别与联系
  20. Spring中开启组件扫描细节配置

热门文章

  1. 陶哲轩实分析 5.5 节习题试解
  2. vgg16网络模型的学习理解
  3. CSS3基础(4)——CSS3 渲染属性
  4. win7安装vmware+ubuntu16.04
  5. 施耐德PLC初始IP地址计算
  6. springboot返回date类型的数据会慢8个小时解决方案
  7. TOJ 3436: 相邻数
  8. 浪潮财务软件 系统表预检查: 对象 ID X。无法使用闩锁类型 SH 读取并闩锁页 。由于不可修复的错误,CHECK 语句已终止。
  9. 危骆邦油邦快讯|一分钟看懂山东地炼成品油报价
  10. base64编码解码讲解