指导Android的文件存储 [英] Guidance on Android file storage

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

问题描述



我需要写一个Android应用程序,将来自互联网为进一步利用下载的声音。


我应该在哪里存储这些声音?是sqlite的一个选择吗?什么是加载和播放这些文件的最好方法?

先谢谢了。


I need to write an Android app that would download sounds from the internet for further use.
Where should i store these sounds? Is Sqlite an option? And what's the best way to load and play these files?
Thanks in advance.

推荐答案

我建议把在SD卡中的文件,如果存在。有一点要注意,不过,是你不应该硬code到SD卡的路径。你可能会想要做的线沿线的东西:

I would recommend putting the files on the SD Card, if one exists. One thing to note, though, is that you should never hard code a path to the SD card. You would likely want to do something along the lines of:

try {
        //Create handle to SD card drectory
        exportDirectory = new File(Environment.getExternalStorageDirectory() + "/MyDir");

        //Verify export path exists.  Create otherwise.
        if (exportDirectory.exists() == false) {
            if (exportDirectory.mkdirs() == false) {

                //Directory structure could not be created.
                //Message the user here
                return false;
            }
        }

        //Create handle to SD card file.
        exportFile = new File(exportDirectory.getAbsolutePath() + "/whatever.mp3");

        //Do whatever here

} catch(Exception e) {
        //Exception.  Message user and bail
        return false;
}

从那里转移你想进入任何文件数据的一个简单的事情。 SQLite数据库很可能会矫枉过正,为这个应用程序,除非你打算存储的额外信息了很多。也没有保证,除非你直接存储文件到数据库为BLOB,用户将不能乱用的应用程序运行之间的文件系统。虽然,在MP3音乐的情况下等,轨道/艺术家类型信息可被直接存储到经由ID3标签的文件,而不是使用一个数据库的

From there it is a simple matter of transferring whatever data you want into the file. An SQLite database would likely be overkill for this app, unless you plan on storing a LOT of extra information. There is also no guarantee, unless you store the files directly into the database as BLOBs, that the user won't mess with the file system between application runs. Though, in the case of MP3s and the like, track / artist type information can be stored directly into the file via ID3 tags instead of using a database.

至于打回文件,征询他们的音频API与Android文档。有一吨的巨大的信息在那里,肯定比我能在这里重复。

As for playing the files back, consult the Android documentation on their audio APIs. There is a ton of great information out there, definitely more than I can repeat here.

这篇关于指导Android的文件存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆