Android, how to choose save file location?

前端 未结 3 1151
孤独总比滥情好
孤独总比滥情好 2021-02-14 09:05

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

thank you!

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-14 09:25

    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

提交回复
热议问题