Android在MTP模式下,只显示指定文件夹

  • Post author:
  • Post category:其他


废话不多说,直切主题

如图:



修改文件夹在PC上的文件夹名



frameworks/base/media/java/android/mtp

下找到

MtpProertyGroup.java

源文件



MtpPropertyList getPropertyList(int handle, int format, int depth)

函数中的

case MtpConstants.PROPERTY_OBJECT_FILE_NAME:

添加如下代码


注意我这里是只修改根目录下的文件,Pictures、Movies、Music分别改成 我的图片、我的视频、我的音乐,parent == 0表示是在根目录

还有一点要注意

int parent = queryInt(handle, Files.FileColumns.PARENT);

中的查询是

    private Integer queryInt(int id, String column) {
        Cursor c = null;
        try {
            // for now we are only reading properties from the "objects" table
            c = mProvider.query(mPackageName, mUri,
                            new String [] { Files.FileColumns._ID, column },
                            ID_WHERE, new String[] { Integer.toString(id) }, null, null);
            if (c != null && c.moveToNext()) {
                return new Integer(c.getInt(1));
            }
        } catch (Exception e) {
        } finally {
            if (c != null) {
                c.close();
            }
        }
        return null;
    }

就这么多了,下一篇关于MTP模式下如何禁止PC端在根目录创建文件夹、修改文件名、删除文件夹等



版权声明:本文为juy19901128原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。