问题描述
我正在尝试将录制的音频文件保存在我想要的文件夹中,而不是默认文件夹中.但不知何故我没有这样做.
i'm trying to save the recorded audio files in a folder that i wanted it to be rather then the default folder. but somehow i failed to do so.
我的代码:
Intent recordIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
Uri mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/Record/sound_"+ String.valueOf(System.currentTimeMillis()) + ".amr"));
recordIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
startActivityForResult(recordIntent, RESULT_OK);
它确实调用了录音机应用程序.而且当我按下停止按钮时,它会返回到我的应用程序并出现一个吐司,说它已保存.但是,不是保存在我的 Record 文件夹中,而是保存在默认文件夹中.
it did calls the voice recorder app. and also when i press the stop button, it return to my app and have a toast appeared saying its saved. but, rather then saving in my Record folder, it save in the default folder.
我意识到 logcat 中有错误消息:
i realized that there is error msg in the logcat :
01-29 01:34:23.900: E/ActivityThread(10824): Activity com.sec.android.app.voicerecorder.VoiceRecorderMainActivity has leaked ServiceConnection com.sec.android.app.voicerecorder.util.VRUtil$ServiceBinder@405ce7c8 that was originally bound here
我不知道哪里出了问题,因为当我调用相机应用程序时代码有效.
i'm not sure what went wrong as the code works when i call the camera app.
推荐答案
我已经找到了解决这个问题的方法,尽管它需要一个回合来完成而不是直截了当,但这是最好的我有,它也能用.
i've found a way to solve this problem, even though it takes a round to do it rather then getting to the point straight, but its the best that i've got and it also work.
我没有调用包含额外内容的录音机应用程序,而是在没有任何输入的情况下调用它:
instead of calling the voice recorder app with extra included, i just call it without any input :
Intent recordIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(recordIntent, 1111);
然后,添加一个 onActivityResult,请求代码 == 1111(取决于您放置的内容)并从记录器声音"的默认文件夹中检索包含扩展名3ga"的最后修改的文件
then, add an onActivityResult, with the request code == 1111 (depends on what you put) and retrieve the last modified file that consist of the extension "3ga" from the default folder of recorder "Sounds"
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1111)
{
File folder = new File(Environment.getExternalStorageDirectory(), "/Sounds");
long folderModi = folder.lastModified();
FilenameFilter filter = new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return (name.endsWith(3ga));
}
};
File[] folderList = folder.listFiles(filter);
String recentName = "";
for(int i=0; i<folderList.length;i++)
{
long fileModi = folderList[i].lastModified();
if(folderModi == fileModi)
{
recentName = folderList[i].getName();
}
}
}
通过这种方式,我可以获得文件的名称并对其进行修改(例如重命名).
this way, i can get the name of the file and also do the modification (e.g renaming) with it.
希望这能帮助其他人.=)
hope this helps other people. =)
这篇关于如何以编程方式将录制的音频文件保存在另一个文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!