Android Call Recording Incoming voice not getting recorded

末鹿安然 提交于 2019-12-17 17:34:23

问题


I'm working auto call recorder app, I'm able to record voice call on below android 6 using MediaRecorder.AudioSource.VOICE_CALL, From android 6 not able to record voice call using VOICE_CALL. I managed to record using MediaRecorder.AudioSource.MIC but here incoming voice not getting recorded and I want to record voice call in normal mode not in speaker on mode. Please help me on this. (I had tried on Xiomi Redmi 4a(android 6),not working).

 myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 myRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
 myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
 myRecorder.setMaxDuration(60 * 60 * 1000);
 AudioManager audiomanager =
 (AudioManager)getSystemService(AUDIO_SERVICE);
 audiomanager.setMode(2);

Edit : There is no issue with permissions.

Update : Anyone knows how to forcing another stream to MIC audio source. This requires native android code. Please help me on this Refer this question for more details on routing audio


回答1:


You need to use ndk. Here are examples of the functions that need to be done.

Load libmedia.so and libutils.so

int load(JNIEnv *env, jobject thiz) {
    void *handleLibMedia;
    void *handleLibUtils;
    int result = -1;
    lspr func = NULL;

    pthread_t newthread = (pthread_t) thiz;

    handleLibMedia = dlopen("libmedia.so", RTLD_NOW | RTLD_GLOBAL);
    if (handleLibMedia != NULL) {
        func = dlsym(handleLibMedia, "_ZN7android11AudioSystem13setParametersEiRKNS_7String8E");
        if (func != NULL) {
            result = 0;
        }
        audioSetParameters = (lasp) func;
    } else {
        result = -1;
    }

    handleLibUtils = dlopen("libutils.so", RTLD_NOW | RTLD_GLOBAL);
    if (handleLibUtils != NULL) {
        fstr = dlsym(handleLibUtils, "_ZN7android7String8C2EPKc");
        if (fstr == NULL) {
            result = -1;
        }
    } else {
        result = -1;
    }

    cmd = CM_D;

    int resultTh = pthread_create(&newthread, NULL, taskAudioSetParam, NULL);

    return result;}

Function setParameters

int setParam(jint i, jint as) {
pthread_mutex_lock(&mt);

audioSession = (int) (as + 1);

kvp = "input_source=4";
kvps = toString8(kvp);

cmd = (int) i;

pthread_cond_signal(&cnd);
pthread_mutex_unlock(&mt);

return 0;}

Task AudioSetParameters

void *taskAudioSetParam(void *threadid) {
    while (1) {
        pthread_mutex_lock(&mt);
        if (cmd == CM_D) {
            pthread_cond_wait(&cnd, &mt);
        } else if (audioSetParameters != NULL) {
             audioSetParameters(audioSession, kvps);
        }
        pthread_mutex_unlock(&mt);
    }
}

There is a library and an example of use https://github.com/ViktorDegtyarev/CallRecLib




回答2:


First these 3 permissions are needed in Manifest as well as a runtime permission request if the device is above Marshmallow,

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />
  1. MediaRecorder.AudioSource.VOICE_CALL is not supported on all phones so you need to continue using MediaRecorder.AudioSource.MIC.

I use this and works fine on most of the devices,

recorder = new MediaRecorder();
  recorder.setAudioSource(audioSource);
  recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  recorder.setOutputFile(your_path);
  1. You need to set this to record your calls properly,

    audioManager.setMode(AudioManager.MODE_IN_CALL);

raise volume level when you start recording audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL), 0);

When you stop recording set the mode to normal, audioManager.setMode(AudioManager.MODE_NORMAL); and also set the stream volume to back how it was.




回答3:


Xiaomi devices always have problems with permission request even run-time or install-time.

I have an Xiaomi Redmi 3 pro, and it always force to Deny some permission when I install apps, so I must manually Allow it. If your problem is the same, I found some workaround solution and it worked for me: How to get MIUI Security app auto start permission programmatically?




回答4:


This could be a Permission related issue.

With the introduction of Android 6.0 Marshmallow, the app will not be granted any permission at installation time. Instead, the application has to ask the user for a permission one-by-one at run-time.

I hope you have included the code which explicitly asks for permissions on devices with Marshmallow and above.




回答5:


In automatic call recorder (callU) have a option "SoundFX" If Enable Record Calls Two Side

Link




回答6:


try

 MediaRecorder.AudioSource.VOICE_COMMUNICATION

and see

https://androidforums.com/threads/android-phone-with-call-recording-function.181663/



来源:https://stackoverflow.com/questions/45231232/android-call-recording-incoming-voice-not-getting-recorded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!