android 根據Uri獲取檔案絕對路徑

2021-06-13 08:26:23 字數 843 閱讀 5488

網上搜尋的**

protected string getabsoluteimagepath(uri uri) ;

cursor cursor = managedquery(uri, proj, // which columns to return

null, // where clause; which rows to return (all rows)

null, // where clause selection arguments (none)

null); // order-by clause (ascending by name)

int column_index = cursor

.getcolumnindexorthrow(mediastore.images.media.data);

cursor.movetofirst();

return cursor.getstring(column_index);

}修改後的**

protected string getabsoluteimagepath(uri uri) ;

cursor cursor = managedquery(uri, proj, // which columns to return

null, // where clause; which rows to return (all rows)

null, // where clause selection arguments (none)

null); // order-by clause (ascending by name)

if (cursor != null) else

}

Android中Java根據檔案頭獲取檔案型別

前面貼過android系統內部的mediafile類來獲取檔案型別的辦法,這個類主要是根據檔案的副檔名來判斷,其準確性不是很好。具體可檢視android系統使用mediafile類判斷音訊檔案型別。其實,獲取檔案型別最好的辦法便是根據檔案頭資訊來判斷。下面貼出相關 public class file...

Android中Java根據檔案頭獲取檔案型別

前面貼過android系統內部的mediafile類來獲取檔案型別的辦法,這個類主要是根據檔案的副檔名來判斷,其準確性不是很好。具體可檢視android系統使用mediafile類判斷音訊檔案型別。其實,獲取檔案型別最好的辦法便是根據檔案頭資訊來判斷。下面貼出相關 public class file...

根據Uri獲取檔案的絕對路徑

public static string getrealpathfromuri context context uri contenturi null null null if cursor null result contenturi getpath else return result 根據的u...