java 在安卓手机上录制电话?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3370278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:32:40  来源:igfitidea点击:

Record phone calls on android phone?

javaandroid

提问by Mobile_Application_Developer

I tried it and use the following code for recording outgoing calls but it does not..

我试过了并使用以下代码记录拨出电话,但它没有..

  @Override
  public void onReceive(Context context, Intent intent) 
  {
          this.context = context;
          if (intent.getAction().equalsIgnoreCase(Intent.ACTION_ANSWER)) 
          {
              try
              {
                  phonenbr = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
                  Log.v("GDHGDHGHDGDHGDHGHDGHDGH", phonenbr);
                  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
                  recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                  recorder.setOutputFile(pathname);
                  recorder.prepare();
                  recorder.start();
                  recordstarted = 1;
                  telManager= (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
              }
              catch(Exception e)
              {
                  e.printStackTrace();
              }


              final PhoneStateListener phoneListener = new PhoneStateListener()
                {
                    @Override
                     public void onCallStateChanged(final int state, final String incomingNumber)
                        {
                            getTelephonyOverview(telManager);
                        }
                };

           telManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

}

}

}

           public void getTelephonyOverview(final TelephonyManager telManager)
           {
                   int callState = telManager.getCallState();
                   switch (callState)
                   {
                    case TelephonyManager.CALL_STATE_IDLE:
                    {
                        if (recordstarted==1)
                        {
                            recorder.stop();
                            recordstarted =0;
                        }
                        break;
                    }
                }
           }

Please provide some good solution for this problem..

请为这个问题提供一些好的解决方案..

回答by Sojan P R

This can be solved with API level 8+. Set your audio source for media recorder as phone uplink, downlink, or both.

这可以通过 API 级别 8+ 来解决。将媒体录音机的音频源设置为电话上行链路、下行链路或两者。

recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); //Voice downlink/ Uplink
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(AudioEncoder.AAC );

But beware of the law and regulations before doing this.

但在这样做之前要注意法律和法规。

回答by CommonsWare

  1. You cannot record phone calls very well in Android, because the in-call audio is not available to SDK applications
  2. ACTION_ANSWERis nota broadcast Intent
  1. 在 Android 中你不能很好地记录电话,因为通话中的音频不适用于 SDK 应用程序
  2. ACTION_ANSWER不是广播Intent

回答by Jaiprakash Soni

You cannot record call simply by media recorder. you have to also change the setting of audio manager and put the loud speaker on before starting recording and the audio source will remain same(mic).So try to edit audio manager's setting

您不能简单地通过媒体录音机记录通话。您还必须更改音频管理器的设置并在开始录制之前打开扬声器,音频源将保持不变(麦克风)。因此请尝试编辑音频管理器的设置



AudioManager audiomanager = (AudioManager)context.getSystemService("audio"); 
int i = audiomanager.getRouting(2); 
audiomanager.setMode(2);
audiomanager.setMicrophoneMute(false);
audiomanager.setSpeakerphoneOn(true); 
int j = audiomanager.getStreamMaxVolume(0); 
if(j < 0) 
     j = 1; 
int k = j / 2 + 1; 
audiomanager.setStreamVolume(0, k, 0); 
audiomanager.setRouting(2, 11, 15);

回答by rjmunro

It seems that you cannot record a call from the API. One common workaround is to engage the speakerphone and record from the microphone - on many devices, the microphone will pick up the speaker adequately with this arrangement.

似乎您无法记录来自 API 的调用。一种常见的解决方法是使用免提电话并从麦克风录音 - 在许多设备上,麦克风将通过这种安排充分拾取扬声器。

Another workaround is to do the recording on a telephony service somewhere and route calls through it.

另一种解决方法是在某处的电话服务上进行录音并通过它路由呼叫。

回答by Mukesh Parmar

This code is working for me to record outgoing phone calls,so please check it Here

此代码适用于我记录拨出电话,因此请在此处查看