简体   繁体   English

android 10 (2019) 是否可以恢复语音通话录音?

[英]Is voice call recording back with android 10 (2019)?

I'm really interested in call recording in android.我对android中的通话录音非常感兴趣。 But as you already know android officially shuts off voice call recording in android 9. But just after the release of Android 10(sept 3 2019), while going through their new release notes, I came across the following page which looked promising, in terms of call recording.但是正如您已经知道的那样,android 正式关闭了 android 9 中的语音通话录音。但就在 Android 10 发布(2019 年 9 月 3 日)之后,在浏览他们的新发行说明时,我发现以下页面看起来很有希望通话录音。 https://developer.android.com/guide/topics/media/sharing-audio-input . https://developer.android.com/guide/topics/media/sharing-audio-input Here regarding voice call recording following things can be seen.在这里,关于语音通话录音可以看到以下内容。

Voice call + ordinary app语音通话+普通APP
A voice call is active if the audio mode returned by AudioManager.getMode() is MODE_IN_CALL or MODE_IN_COMMUNICATION.如果 AudioManager.getMode() 返回的音频模式为 MODE_IN_CALL 或 MODE_IN_COMMUNICATION,则语音呼叫处于活动状态。

Android shares the input audio according to these rules: Android 根据以下规则共享输入音频:

The call always receives audio.呼叫始终接收音频。 The app can capture audio if it is an accessibility service.如果应用程序是无障碍服务,则它可以捕获音频。 The app can capture the voice call if it is a privileged (pre-installed) app with permission CAPTURE_AUDIO_OUTPUT.如果应用程序是具有 CAPTURE_AUDIO_OUTPUT 权限的特权(预安装)应用程序,则该应用程序可以捕获语音通话。

To capture the voice call's uplink (TX), downlink (RX), or both, the app must specify the audio sources MediaRecorder.AudioSource.VOICE_UPLINK or MediaRecorder.AudioSource.VOICE_DOWNLINK, and/or the device AudioDeviceInfo.TYPE_TELEPHONY.要捕获语音呼叫的上行链路 (TX)、下行链路 (RX) 或两者,应用程序必须指定音频源 MediaRecorder.AudioSource.VOICE_UPLINK 或 MediaRecorder.AudioSource.VOICE_DOWNLINK,和/或设备 AudioDeviceInfo.TYPE_TELEPHONY。

So after reading this I tried to capture audio inside an accessibility service.因此,在阅读本文后,我尝试在无障碍服务中捕获音频。 Here's my code.这是我的代码。 Accessibility service无障碍服务

 public class MyAccessibilityService extends AccessibilityService { FrameLayout mLayout; public MyAccessibilityService() { } @Override public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) { } @Override public void onInterrupt() { } @Override protected void onServiceConnected() { WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); mLayout = new FrameLayout(this); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY; lp.format = PixelFormat.TRANSLUCENT; lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; lp.width = WindowManager.LayoutParams.WRAP_CONTENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; lp.gravity = Gravity.TOP; LayoutInflater inflater = LayoutInflater.from(this); inflater.inflate(R.layout.action_bar, mLayout); wm.addView(mLayout, lp); configureStartRecording(); configureStopRecording(); } private void configureStartRecording() { Button startRecordingButton = mLayout.findViewById(R.id.btnStartRecording); startRecordingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { CustomMediaRecorder recorder = CustomMediaRecorder.getInstance(); File audiofile = null; String out = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date()); File sampleDir = new File(getExternalFilesDir(null), "/TestRecordingDasa1"); if (!sampleDir.exists()) { sampleDir.mkdirs(); } String file_name = "Record"; try { audiofile = File.createTempFile(file_name, ".amr", sampleDir); } catch (IOException e) { e.printStackTrace(); } recorder.getRecorder().setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); recorder.getRecorder().setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); recorder.getRecorder().setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.getRecorder().setOutputFile(audiofile.getAbsolutePath()); try { recorder.getRecorder().prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } recorder.start(getApplicationContext()); Log.i(MainActivity.LOG_PREFIX, String.format("Recording started. Saving to path: '%s'", audiofile.getAbsolutePath())); } }); } private void configureStopRecording() { Button button = mLayout.findViewById(R.id.btnStopRecording); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { CustomMediaRecorder recorder = CustomMediaRecorder.getInstance(); recorder.stop(); } }); }

And The accessibility service config has the following configs并且无障碍服务配置具有以下配置

 android:accessibilityFeedbackType="feedbackGeneric" android:accessibilityFlags="flagDefault" android:canPerformGestures="true" android:canRetrieveWindowContent="true"

So here are my observations.所以这是我的观察。
1. Still we cannot set MediaRecorder.AudioSource.VOICE_DOWNLINK and VOICE_UPLINK audio sources. 1. 仍然无法设置MediaRecorder.AudioSource.VOICE_DOWNLINK 和VOICE_UPLINK 音频源。 It fires an exception.它引发异常。
2. When MediaRecorder.AudioSource.VOICE_COMMUNICATION and MediaRecorder.AudioSource.MIC is given mic input prior to starting the call and after disconnecting the call is recorded. 2. 当 MediaRecorder.AudioSource.VOICE_COMMUNICATION 和 MediaRecorder.AudioSource.MIC 在开始通话之前和断开通话后被给予麦克风输入时。

So it looks like we are not getting any stream from the call even from an accessibility service.所以看起来我们甚至从无障碍服务中也没有从呼叫中获得任何流。 I tried this on a pixel 3A xl device which is newly updated to android 10.我在新更新到 android 10 的像素 3A xl 设备上尝试了这个。

So after reading this, and after my failed trial I have following questions...所以在读完这篇文章后,在我失败的审判之后,我有以下问题......

  1. What does this new behavior for android 10 really mean. android 10 的这种新行为到底意味着什么。 What is the relevance here for an accessibility service?无障碍服务与此有何相关性? Which I tried and already failed?我尝试过但已经失败了?
  2. Have I done anything wrong during configuring the accessibility service?我在配置无障碍服务时做错了什么吗?
  3. If this approach does not solve call recording issue is android 10 also missing with the call recording feature?如果这种方法不能解决通话录音问题,那么 android 10 是否也缺少通话录音功能? Or is there any other way of doing it in android 10. Because I'm only interested in call recording in android 10.或者有没有其他方法可以在 android 10 中做到这一点。因为我只对 android 10 中的通话录音感兴趣。

In a nutshell I just want to know whether voice call recording is back with android 10...简而言之,我只想知道 android 10 是否恢复了语音通话录音...

First of all thanks for your code.首先感谢您的代码。 I tried with the same code and I have used MediaRecorder.AudioSource.VOICE_RECOGNITION and I am getting both side call recording in Samsung S10, Oneplus 7 and Real Me.我尝试使用相同的代码,并且使用了MediaRecorder.AudioSource.VOICE_RECOGNITION并且我在三星 S10、一加 7 和 Real Me 中获得了双方的通话录音。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM