Android, how to choose save file location?

廉价感情. 提交于 2019-12-04 18:31:50

问题


is there any solution how to choose the saving files location? maybe with the original file browser, to choose the destination?

thank you!


回答1:


All you need is Android Directory Picker




回答2:


Better to save files with your app namespace:

String extStorage = Environment.getExternalStorageState();
path = extStorage+"/Android/data/com.mydomain.myapp/";

It will be deleted when app gets uninstalled.

Here is actually everything about data storing.
http://developer.android.com/guide/topics/data/data-storage.html

From the above link:

If you're using API Level 7 or lower, use getExternalStorageDirectory(), to open a File representing the root of the external storage. You should then write your data in the following directory:

/Android/data/<package_name>/files/



回答3:


It's probably easiest and expected to save this out to the dedicated area on the external SD card.

You can get this folder by calling

file://localhost/Applications/android-sdk-macosx/docs/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)

File path = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES)

You can also append a sub-folder to reference the source better ie. your app.

You can either choose DIRECTORY_PICTURES or DIRECTORY_MOVIES. If it's user created I'd probably stick to pictures.

To be helpful you can also call the media scanner to add it to the appropriate content provider system wide.

sendBroadcast( new Intent(Intent.ACTION_MEDIA_MOUNTED, 
                    Uri.parse("file://" + Environment.getExternalStorageDirectory()))
        );

If you MUST get a file chooser going, which isn't the recomened approach to expose the user to the file system. Try the file chooser form Open Intents. http://www.openintents.org/en/node/164



来源:https://stackoverflow.com/questions/11848224/android-how-to-choose-save-file-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!