Android 解析标准的点击第三方文件管理器中的视频的intent
解析标准的第三方视频intent
private List<String> mCurPlayList = new ArrayList<String>();
private int mCurPosition = 0; // 当前的位置信息
if (intent != null && TextUtils.equals(intent.getAction(), Intent.ACTION_VIEW)
&& !TextUtils.isEmpty(intent.getType()) && intent.getType().contains("video")) {
// 用来解析标准的第三方视频intent
String data = intent.getDataString(); // 这个地方获取的是乱码需要解析 file:///mnt/udisk2/%E7%BE%A4%E6%98%9F%20-%20%E5%8C%97%E4%BA%AC%E7%A5%9D%E7%A6%8F%E4%BD%A0.mp4
String folder = data;
if (!TextUtils.isEmpty(data)) {
if (data.startsWith("file://")) {
data = Uri.decode(data).substring(7);
Logcat.d("initData replaceFirst data " + data);
}
if (data.lastIndexOf("/") > 0) {
folder = data.substring(0, data.lastIndexOf("/"));
Logcat.d("initData substring folder " + folder);
}
File file = new File(folder);
VideoUtils.GetVideoFile(mCurPlayList, file);
if (mCurPlayList != null && mCurPlayList.size() > 0) {
mCurPosition = mCurPlayList.indexOf(data);
}
}
Logcat.d("initData " + data + "; mCurPosition " + mCurPosition);
}
// 遍历指定目录的视频文件
public static void GetVideoFile(final List<String> mList, File file) {
if (mList == null) {
Logcat.w("mList is null ");
return;
}
if (file == null) {
Logcat.w("file is null ");
return;
}
mList.clear();
file.listFiles(new FileFilter() { @Override
public boolean accept(File file) {
if (FileUtils.isVideo(file)) {
mList.add(file.getAbsolutePath());
Logcat.d("initData AbsolutePath " + file.getAbsolutePath());
return true;
}
return false;
}
});
}
/** whether the file is video */
public static boolean isVideo(File file) {
String surfix = getFileSurfix(file);
return (surfix.equals("avi") || surfix.equals("mp4")
|| surfix.equals("3gp") || surfix.equals("rmvb")
|| surfix.equals("mov") || surfix.equals("wmv")
|| surfix.equals("mpeg") || surfix.equals("mpg")
|| surfix.equals("rm") || surfix.equals("vob")
|| surfix.equals("mkv") || surfix.equals("flv")
|| surfix.equals("asp") || surfix.equals("ASF")
|| surfix.equals("m2ts") || surfix.equals("ts")
|| surfix.equals("divx"));
}
/** Get file suffix from file path */
public static String getFileSurfix(File file) {
String surfix = ""; if (file != null) {
String filePath = file.getAbsolutePath();
surfix = getFileSurfix(filePath);
}
return surfix.toLowerCase();
}
/** Get file suffix from file path */
public static String getFileSurfix(String filePath) {
String surfix = ""; if (filePath != null) {
int surfixPos = filePath.lastIndexOf(".");
int surfixPosDivider = filePath.lastIndexOf("/");
// invalid : abcdefg.hijk/lmn
if (surfixPos > 0 && surfixPos > surfixPosDivider)
surfix = filePath.substring(surfixPos + 1, filePath.length());
} return surfix.toLowerCase();
}
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data
android:mimeType="video/*"
android:scheme="http" />
<data
android:mimeType="video/*"
android:scheme="file" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
打印的日志:
11-02 09:34:03.739 2469-2469/? D/RRIVI: VideoPlayerActivity.java(318):initData: initData replaceFirst data /mnt/udisk2/Lady.GaGa.-.Poker.Face.avi
11-02 09:34:03.740 2469-2469/? D/RRIVI: VideoPlayerActivity.java(322):initData: initData substring folder /mnt/udisk2
11-02 09:34:03.744 2469-2469/? D/RRIVI: VideoUtils.java(86):accept: initData AbsolutePath /mnt/udisk2/Wildlife.wmv
11-02 09:34:03.744 2469-2469/? D/RRIVI: VideoUtils.java(86):accept: initData AbsolutePath /mnt/udisk2/江南丝带舞.mp4
11-02 09:34:03.745 2469-2469/? D/RRIVI: VideoUtils.java(86):accept: initData AbsolutePath /mnt/udisk2/群星 - 北京祝福你.mp4
11-02 09:34:03.746 2469-2469/? D/RRIVI: VideoUtils.java(86):accept: initData AbsolutePath /mnt/udisk2/少女时代的-My Oh My.mp4
11-02 09:34:03.746 2469-2469/? D/RRIVI: VideoUtils.java(86):accept: initData AbsolutePath /mnt/udisk2/Lady.GaGa.-.Poker.Face.avi
11-02 09:34:03.747 2469-2469/? D/RRIVI: VideoUtils.java(86):accept: initData AbsolutePath /mnt/udisk2/mv_少女时代 - Gee.rmvb
11-02 09:34:03.747 2469-2469/? D/RRIVI: VideoPlayerActivity.java(330):initData: initData /mnt/udisk2/Lady.GaGa.-.Poker.Face.avi; mCurPosition 4
Android 解析标准的点击第三方文件管理器中的视频的intent的更多相关文章
- Android studio3.0打开Device File Explore(文件管理器)的方法(图文教程)
Android studio3.0打开Device File Explore(文件管理器)的方法(图文教程) 看到网上AS3.0新增加的查看手机文件的新功能,全部都是转载的,没有几个人心细的把如何打开 ...
- 在Windows操作系统的文件管理器中集成Azure DevOps Server (TFS)工具菜单
故事场景 使用过SVN的用户,都知道在Windows的文件夹上点击鼠标右键,就会弹出Tortoise SVN的操作菜单(俗称小乌龟).通过这个功能,用户不需要打开SVN工具,可以直接在Windows的 ...
- eclipse 怎么 直接查看 文件所在位置 显示在文件管理器中。用浏览器浏览。
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha eclipse 怎么 直接查看 文件所在位置 显示在文件管理器中.用浏览器浏览.
- Android为TV端助力 集成第三方播放器,实现全屏播放
下面这Demo链接:Android实现全屏播放,各种格式支持直播,点播,不收费!
- android混淆打包配置(忽略第三方jar)
在project.properties里加上 proguard.config=proguard.cfg proguard.cfg 配置如下: -optimizationpasses 5-dontu ...
- 免费的在线Web文件管理器:Net2FTP,Pydio,eXtplorer,KodExplorer–功能强大
https://www.freehao123.com/web-ftp/ 经常有朋友在使用一些没有带文件管理器的空间时,苦于没有办法来解压上传的文件压缩包,而如果不先上传压缩包,直接上传文件夹的话耗费的 ...
- [转帖]使用Gnome文件管理器连接到服务器:FTP/SFTP、Samba、NFS的方法
使用Gnome文件管理器连接到服务器:FTP/SFTP.Samba.NFS的方法 2019-05-09 16:28:44作者:雷增线稿源:云网牛站 https://ywnz.com/linuxyffq ...
- Android中调用文件管理器并返回选中文件的路径
实际项目中经常需要调用文件管理器,选择下载路径或者上传的本地文件路径.今天就给大家做个demo示范该功能的实现过程. 一.实现效果预览 以下为三星S6的样机测试效果,当然不同手机调用后的效果不一样. ...
- Android解析编译之后的所有文件(so,dex,xml,arsc)格式
我们在之前一篇一篇介绍了如何解析Android中编译之后的所有文件格式,所有的工作都完成了,这里我们就来做个总结,我们为什么要做这些工作: 第一篇:解析so文件格式 点击进入 这里我们解析so文件,主 ...
随机推荐
- PHP GZIP压缩+BASE64
<?php $str = ' {"pf":"AC25c","dt":"2017-02-04 09:49:49",& ...
- [Swift]LeetCode78. 子集 | Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solut ...
- [Swift]LeetCode162. 寻找峰值 | Find Peak Element
A peak element is an element that is greater than its neighbors. Given an input array nums, where nu ...
- [Swift]LeetCode232. 用栈实现队列 | Implement Queue using Stacks
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
- [Swift]LeetCode699. 掉落的方块 | Falling Squares
On an infinite number line (x-axis), we drop given squares in the order they are given. The i-th squ ...
- [Swift]LeetCode973. 最接近原点的 K 个点 | K Closest Points to Origin
We have a list of points on the plane. Find the K closest points to the origin (0, 0). (Here, the d ...
- Netty:ChannelInitializer
1. 作用 用于在某个Channel注册到EventLoop后,对这个Channel执行一些初始化操作.ChannelInitializer虽然会在一开始会被注册到Channel相关的pipeline ...
- .NET Core实战项目之CMS 第十一章 开发篇-数据库生成及实体代码生成器开发
上篇给大家从零开始搭建了一个我们的ASP.NET Core CMS系统的开发框架,具体为什么那样设计我也已经在第十篇文章中进行了说明.不过文章发布后很多人都说了这样的分层不是很合理,什么数据库实体应该 ...
- Dockerfile指令介绍
FROM:指定基础镜像 在Dockerfile中FROM是必备的指令,用于指定基础的镜像. FROM centos:latest LABEL:指定镜像标签 LABEL指令用来指定镜像的标签. 格式: ...
- .NET Core中的CSV解析库
感谢 本篇首先特别感谢从此启程兄的<.NetCore外国一些高质量博客分享>, 发现很多国外的.NET Core技术博客资源, 我会不定期从中选择一些有意思的文章翻译总结一下. .NET ...