通常的獲取sdcard的路徑,我們會用environment.getexternalstoragedirectory(),但是當我們的裝置有多個外部儲存裝置,environment就顯得捉襟見肘了。那麼有什麼方法可以解決這種問題?看下面的方法,通過反射的方式獲取外部儲存裝置的路徑,完美解決 nice。
我們看下通過getvolumepaths方法獲取到我的android裝置上有哪些外設路徑private string getvolumepaths() ;
method getvolumepathsmethod = storagemanager.class.getmethod("getvolumepaths", paramclasses);
getvolumepathsmethod.setaccessible(true);
object params = {};
paths = (string) getvolumepathsmethod.invoke(storagemanager, params);
} catch (nosuchmethodexception e) catch (illegalargumentexception e) catch (illegalacces***ception e) catch (invocationtargetexception e)
return paths;
}
從log中我們可以看到,我的android裝置有3種外設,分別是,內建的sdcard,外接的sdcard,以及u盤。可以看到getvolumepaths方法確實要比environment.getexternalstoragedirectory強大,對於需要獲取全部外設路徑的專案用此方法非常管用,特此記下。
Android外部儲存 內部儲存路徑獲取大全
package com.mufeng.toolproject.utils import android.content.context import android.os.environment created by mufeng on 2017 3 11.public class director...
Android外部儲存
外部儲存 public class externalstorgautils return bl 根據type型別判斷該file檔案是否存在 param type 檔案型別 return 是否存在 public static boolean ha ternalstoragetype string ty...
android 獲取 內外儲存裝置路徑疑問
android 系統是開源的,於是各種產商各種瞎改android系統,工作了幾個月,我發現單單就android的內外儲存裝置的路徑我就不知道怎麼獲取了。上網查了幾種方案,自己試驗了下,感覺好迷茫啊。在這裡記錄下我試驗的幾種方案。方案一 通過enviroment類獲取儲存裝置路徑 android的官方...