我正在開發Android應用程序。有一兩件事我注意到的是,當我想使用的存儲,基本上有兩種選擇對我來說:Android手機存儲
使用包存儲(下面的代碼):
public static String getPackagePath(Activity activity){ return activity.getFilesDir().toString(); }
,如果有一個SD卡,我可以使用外部存儲:
/** * check if the phone has SD card * @return */ public static boolean hasSDCard(){ boolean fHasSDCard = false; if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){ fHasSDCard = true; } return fHasSDCard; } /** * get external storage directory path * @return */ public static String getExternalStoragePath(){ String strPath = ""; if(hasSDCard()){ strPath = Environment.getExternalStorageDirectory().getPath(); } return strPath; }
現在我的代碼對SD卡的情況下主要是繼電器,而且很可能將打破如果T這裏沒有SD卡。我的問題是,有沒有SD卡的任何Android設備?如果沒有SD卡,是將數據放入包路徑的正確方法嗎?
謝謝
沒有*假設*是與Google Play *一起銷售的任何設備*,它原本沒有外部存儲設備,但是如果可移動,則可以將其移除,並且在具有USB大容量存儲設備的版本中,由於被掛載通過USB連接到PC。或者它可能已經滿員或者已經損壞/腐敗。所以是的,它並不總是可用的。但是有很多應用程序會抱怨和禁用功能(而不是崩潰),如果不是的話。 –