Answers
音频也是在onActivityResult中获取
调用系统音频:
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(intent, RECORD_AUDIO);
获取Uri:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case RECORD_AUDIO:
try {
Uri uri = data.getData();
String filePath = getAudioFilePathFromUri(uri);
Log.d(TAG, filePath);
} catch (Exception e) {
throw new RuntimeException(e);
}
break;
}
}
private String getAudioFilePathFromUri(Uri uri) {
Cursor cursor = getContentResolver()
.query(uri, null, null, null, null);
cursor.moveToFirst();
int index = cursor.getColumnIndex(MediaStore.Audio.AudioColumns.DATA);
return cursor.getString(index);
}
filePath就是你录的音频文件,你可以copy到任何位置。
不用忘记添加uses-permission相关权限
xfznyb
answered 9 years, 7 months ago