不喜欢这样的方式,
Intent i = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
i.putExtra(MediaStore.EXTRA_OUTPUT, myAudio);
然后创建onActivityResult
并添加以下代码。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode,
resultCode, data);
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case CAPTURE_AUDIO:
Uri audioUri = data.getData();
String absolutepath = getRealPathFromURI(audioUri);
String path2 = Environment.getExternalStorageDirectory()
+ "/Ringtone/";
File file = new File(absolutepath);
File file2 = new File(path2 + "RecordedAudio.3gpp");
file.renameTo(file2);
break;
default:
break;
}
}
}
这里是你的getRealPathFromURI
方法。
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Audio.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
cursor.moveToFirst();
System.out.println("absolutepath audiopath in getRealPathFromURI : "
+ cursor.getString(column_index));
return cursor.getString(column_index);
}
肯定这会为你工作。
由于您正在删除目录myAudioFile.delete();'删除此行,您就完成了。 – InnocentKiller
已删除,但仍未解决 – Sun
因为您正在使用Intent录制默认录音机的音频,因此无论您提供什么路径,它都会将录制的音频存储到默认目录。解决方案是您必须获取上次录制音频的路径,然后您必须将该文件移动或复制到目标位置。 – InnocentKiller