[英]Call Recording App not working in android above OS version 7.0
I am developing call recording app which is working fine upto OS version 6.0 of android but it stops recording incoming call voice on and above OS version 7.0. 我正在开发通话记录应用程序,该应用程序在Android OS版本6.0之前都可以正常工作,但是在OS版本7.0及更高版本上它会停止记录来电语音。 I am using
MediaRecorder.AudioSource.VOICE_CALL
and MediaRecorder.AudioSource.VOICE_COMMUNICATION
both as per device requirement. 我正在根据设备要求同时使用
MediaRecorder.AudioSource.VOICE_CALL
和MediaRecorder.AudioSource.VOICE_COMMUNICATION
。 Providing code below, 在下面提供代码,
private boolean startMediaRecorder(int audioSource){
recorder = new MediaRecorder();
try{
recorder.reset();
recorder.setAudioSource(audioSource);
recorder.setAudioSamplingRate(8000);
recorder.setAudioEncodingBitRate(12200);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
fileName = FileHelper.getFilename(phoneNumber,type,getApplicationContext());
recorder.setOutputFile(fileName);
OnErrorListener errorListener = new OnErrorListener() {
public void onError(MediaRecorder arg0, int arg1, int arg2) {
Log.e(Constants.TAG, "OnErrorListener " + arg1 + "," + arg2);
terminateAndEraseFile();
}
};
recorder.setOnErrorListener(errorListener);
OnInfoListener infoListener = new OnInfoListener() {
public void onInfo(MediaRecorder arg0, int arg1, int arg2) {
Log.e(Constants.TAG, "OnInfoListener " + arg1 + "," + arg2);
terminateAndEraseFile();
}
};
recorder.setOnInfoListener(infoListener);
recorder.prepare();
// Sometimes prepare takes some time to complete
Thread.sleep(2000);
recorder.start();
recording = true;
return true;
}catch (Exception e){
e.getMessage();
return false;
}
}
private void startRecording(Intent intent) {
Log.d(Constants.TAG, "RecordService startRecording");
boolean exception = false;
if (!startMediaRecorder(MediaRecorder.AudioSource.VOICE_CALL)){
if(startMediaRecorder(MediaRecorder.AudioSource.MIC)){
audioManager =(AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setStreamVolume(3,audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL),0);
Intent intent1 = new Intent(getBaseContext(), DialogConfirmActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
}else{
exception = true;
}
}
if (exception) {
terminateAndEraseFile();
}
if (recording) {
Toast toast = Toast.makeText(this,
this.getString(R.string.receiver_start_call),
Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(this,
this.getString(R.string.record_impossible),
Toast.LENGTH_LONG);
toast.show();
}
}
I have enabled permissions in android manifests but it requires CAPTURE_AUDIO_OUTPUT
permission to record voice at both end which is system level permission so I am facing difficulties in granting such permission. 我已经在android清单中启用了权限,但是它需要
CAPTURE_AUDIO_OUTPUT
权限才能在两端记录语音(这是系统级别的权限),因此在授予此类权限时遇到了困难。 Please suggest me a way to grant such permission or any alternate way to enable MediaRecorder.AudioSource.VOICE_CALL
method in all devices. 请为我建议一种授予此类权限的方法,或者是在所有设备中启用
MediaRecorder.AudioSource.VOICE_CALL
方法的任何替代方法。
From Android M and above you need to ask permission at run-time. 在Android M及更高版本中,您需要在运行时请求权限。 You can declare the permission in Manifest as,
您可以在清单中将许可声明为,
<uses-permission android:name="android.permission.RECORD_AUDIO" />
And then ask for the same during onCreate of your launcher activity. 然后在启动器活动的onCreate期间要求相同。 Check this link for detailed explanation.
检查此链接以获取详细说明。 Also make sure that you use
VOICE_COMMUNICATION
instead of VOICE_CALL
which is deprecated now. 另外,还要确保您使用
VOICE_COMMUNICATION
代替VOICE_CALL
现在已经过时了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.