Android在MTP模式下,只顯示指定文件夾

廢話不多說,直切主題

如圖:


修改文件夾在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端在根目錄創建文件夾、修改文件名、刪除文件夾等



發佈了27 篇原創文章 · 獲贊 4 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章