android MTP 过滤指定的文件格式

    这两天在研究android mtp模式过滤文件系统格式,比如.wave等格式,在mtp目录不显示。

直接上改动的地方:

diff --git a/media/java/android/mtp/MtpPropertyGroup.java b/media/java/android/mtp/MtpPropertyGroup.java
index dea300838..f4d688575 100644
--- a/media/java/android/mtp/MtpPropertyGroup.java
+++ b/media/java/android/mtp/MtpPropertyGroup.java
@@ -291,8 +291,13 @@ class MtpPropertyGroup {
         return path.substring(start, end);
     }
 
+    private static boolean fileIsWave(String name) {
+        Log.e(TAG, "===========" + name);
+        return name != null && name.indexOf(".wave") != -1;
+        //return false;
+    }

     MtpPropertyList getPropertyList(int handle, int format, int depth) {
        Log.d(TAG, "getPropertyList handle: " + handle + " format: " + format + " depth: " + depth);
         if (depth > 1) {
             // we only support depth 0 and 1
             // depth 0: single object, depth 1: immediate children
@@ -365,7 +370,7 @@ class MtpPropertyGroup {
                         case MtpConstants.PROPERTY_OBJECT_FILE_NAME:
                             // special case - need to extract file name from full path
                             String value = c.getString(column);
-                            if (value != null) {
+                            if ((value != null)&&(!fileIsWave(nameFromPath(value)))) {
                                 result.append(handle, propertyCode, nameFromPath(value));
                             } else {
                                 result.setResult(MtpConstants.RESPONSE_INVALID_OBJECT_HANDLE);

 

这样的话,就把wave格式文件设置为INVALID_OBJECT,从而界面上无法显示。也就是起到了过滤的作用。

别看这么两行,也是折腾了两天才找到具体要修改的代码点,功能实现了,就是高兴啊!!!!

 

Mark 一下!!!

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(android)