2011-12-23 185 views
0

可能重複:
store an image in internal storage in android如何在內部存儲器中保存圖像?

如何保存圖像在內部存儲?我需要確保用戶存儲圖像時沒有SD卡(直到現在我一直在使用Environment.getExternalStorageDirectory()將圖像存儲在EXTRA_OUTPUT中)。任何人都可以幫助,我需要存儲圖像的URI?

+2

我相信這不是一個preferrable存儲在內部存儲的圖像,你知道的內部存儲空間的大小來在Android設備?其大部分大約在256MB,512MB等等,並用於應用程序內部目的,系統管理等。 – 2011-12-23 12:34:53

+0

從您的上下文中調用getFilesDir() [Documentation here](http://developer.android.com/reference/ android/content/ContextWrapper.html#getFilesDir%28%29) – daveD 2011-12-23 12:36:21

+0

我不確定....但你可以通過這個..... http://stackoverflow.com/questions/5766579/store-an- image-in-internal-storage-in-android http://developer.android.com/reference/android/provider/MediaStore.Images.Media.html – 2011-12-23 12:38:56

回答

3

您可以直接在設備的內部存儲器上保存文件。默認情況下,保存到內部存儲的文件對您的應用程序是私人的,其他應用程序無法訪問它們。當用戶卸載您的應用程序時,這些文件將被刪除。

下面的腳本會告訴你如何保存文件中的android:

String FILENAME = "my_file"; 
    String string = "Schogini Systems"; 

    FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); 
    fos.write(string.getBytes()); 
    fos.close(); 
+0

+ 1,應接受此答案作爲解決方案 – 2013-01-08 09:45:25

+0

此解決方案不適用於圖像,因爲getBytes()不適用於位圖類型 – anirus 2014-01-17 04:37:34

相關問題