Android : 将文件保存到 SD 卡

Android : Saving Files to SD Card(Android : 将文件保存到 SD 卡)

本文介绍了Android : 将文件保存到 SD 卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的应用程序中的文件保存到设备的外部存储中.具体来说,我正在尝试保存声音.

I am trying to save a file out from within my app to the external storage of a device. Specifically, I am trying to save a sound out.

我已经按照每个教程"进行此操作,没有一个对我来说特别令人困惑,但它对我不起作用.根本不会在 SD 卡上创建文件,更不用说实际传输信息了.

I've followed every 'tutorial' on doing this, and none of it seemed particularly confusing to me, yet it just will not work for me. No file is ever created on the SD card at all, much less actually transferring over the information.

我假设我没有得到正确的卡片路径,但无论我尝试了什么,它都不起作用.我尝试只输入/sdcard/",以及使用 getExternalStorageDirectory() 方法,以及其他随机实验.

I've assumed I am somehow not getting the correct path to the card, but no matter what I have tried it doesn't work. I have tried entering just "/sdcard/", as well as using the getExternalStorageDirectory() method, among other random experiments.

花了半天多的时间在一些看起来如此微不足道的事情上,我什至无法再思考了,所以我希望你能原谅我提供的一些缺乏细节,但任何建议都会对此有所帮助点.

After spending over half the day on something that would seem so trivial I can't even think straight anymore, so I hope you will excuse some of the lack of detail I'm providing, but any suggestion would be helpful at this point.

推荐答案

您确定文件没有保存到 SD 卡吗?我以为我遇到了同样的问题.事实证明,我一直正确地保存到 SD 卡,但画廊没有被刷新以显示我刚刚保存的文件.使用 Astro 文件管理器确保文件尚未保存到卡中.如果这是问题所在,请添加此行以刷新图库:

Are you absolutely certain the file isn't being saved to the SD card? I thought I was having the same problem. It turned out that I was saving correctly to the SD card the whole time, but the gallery wasn't being refreshed to show the files I had just saved. Use Astro File Manager to make sure the file isn't already being saved to the card. If this is the problem, add this line to refresh the gallery:

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

这篇关于Android : 将文件保存到 SD 卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android : 将文件保存到 SD 卡

基础教程推荐