效果图
使用
1 - 在AndroidManifest.xml 中设置权限
request for them in Android 6.0+
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
2 - 打开记录的Activity
String filePath = Environment.getExternalStorageDirectory() + "/audio.wav";
int color = getResources().getColor(R.color.colorPrimaryDark);
int requestCode = 0;
AndroidAudioRecorder.with(this)
.setFilePath(filePath)
.setColor(color)
.setRequestCode(requestCode)
.record();
3 - 等待结果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RECORD_AUDIO) {
if (resultCode == RESULT_OK) {
// Great! User has recorded and saved the audio file
} else if (resultCode == RESULT_CANCELED) {
// Oops! User has canceled the recording
}
}
}
导入工程
在 app/build.gradle加入下行:
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.github.adrielcafe:AndroidAudioRecorder:0.0.3'
}