26

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Bharath Kumar
  • 534
  • 1
  • 7
  • 18

6 Answers6

11

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

  • @ishmaelMakitla Sorry. Edited. – Viktor Degtyarev Oct 18 '17 at 07:52
  • Hi @Viktor Degtyarev thanks for your answer, It is actually working. If you explain your answer in explanation its more helpful. (Sorry for the late response, actually I was working on the other projects.) – Bharath Kumar Jan 04 '18 at 07:48
  • Hi Viktor will this library work on Samsung S7 and S8 (Noughat Devices) as i am having trouble recording incoming voice during a call. Please help – Akshat Vajpayee Jan 22 '18 at 07:50
  • Hi @BharathKumar please help how did you manage to use above code to record incoming voice also please provide the source code. – Akshat Vajpayee Jan 24 '18 at 12:49
  • @ViktorDegtyarev other user's voice is still recording so much low in mi device. Did you have any solution for this? – curiousMind Jun 28 '18 at 13:26
  • Where and how to add above NDK code ?. I have no knowledge on NDK.please help me on this for recording call. – Naveen Aug 11 '19 at 06:29
  • on Android 9 this library not making any difference then just recording audio with android MediaRecorder and audio source MIC, was investigating all possibilities to record incoming call audio, also was researching other apps. Only solution is Volume up a microphone and hope that caller will talk loud. All recording apps on Google Play are based on this logic... – Antonis Radz Aug 27 '19 at 08:02
4

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?

nhoxbypass
  • 9,695
  • 11
  • 48
  • 71
  • Thanks for your answer. But the problem is during call recording other side voice is not getting recording. Only my voice is getting recorded. – Bharath Kumar Aug 07 '17 at 07:19
  • have you got solution of this? i also have the same problem in Samsung Galaxy s7, s8 – Bhanu Sharma Aug 28 '17 at 05:28
  • HI all i faced same issue( Not getting other side voice ) with Samsung S7 and S8 other wise my prog is run very well on rest of phones Any idea about ?? – Bhanu Sharma Aug 30 '17 at 12:12
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.

Community
  • 1
  • 1
oldcode
  • 1,669
  • 3
  • 22
  • 41
  • Thanks for your answer. But the Incoming voice is very very low(Negligible voice coming). (Tested on :Xiomi Redmin 4A android 6) – Bharath Kumar Jul 21 '17 at 07:42
  • Are you properly raising the volume in the audio manager ? I have tested on Redmi Note 3,Samsung Galaxy J2,Coolpad,Samsung Galaxy 2 duos, it is working fine.. – oldcode Jul 21 '17 at 10:11
  • @BharathKumar Let me know if you need more help as I have accomplished this before and know what works and what not.. – oldcode Jul 21 '17 at 10:12
  • Yeah I used audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL), 0); to raise volume. Outgoing voice is fine, problem only with incoming voice. Issue is on Redmi 4A. Please help me on this. – Bharath Kumar Jul 21 '17 at 10:27
  • @BharathKumar Can you please create a chat room, lets discuss this over there ? – oldcode Jul 21 '17 at 12:19
  • 1
    HI all i faced same issue( Not getting other side voice ) with Samsung S7 and S8 other wise my prog is run very well on rest of phones Any idea about ?? – Bhanu Sharma Aug 30 '17 at 12:11
  • 1
    Have you found the solution to this?, if yes could please share it – 123Ex Dec 21 '17 at 10:34
  • @BhanuSharma Have you found a solution for this? I also tried on Galaxy S7 (Android 8.0) and it doesn't work, yet on this app it works fine: https://play.google.com/store/apps/details?id=com.boldbeast.recorder&hl=en . Wrote about this here: https://stackoverflow.com/q/50970915/878126 – android developer Jun 25 '18 at 13:54
  • No i didn't find anything about it – Bhanu Sharma Jun 26 '18 at 09:43
  • Outgoing voice is fine, problem only with incoming voice. Issue is on Redmi 4A. Please help – Saurabh Gaddelpalliwar Feb 07 '19 at 11:01
1

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.

Marlon
  • 1,839
  • 2
  • 19
  • 42
  • There is no issue with permissions, its recording and creating file in sdcard. Thing is my side voice is getting recorded, other side voice is not coming. And its working fine on oneplus 5 with android 7 – Bharath Kumar Jul 21 '17 at 07:25
1

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

Link

enter image description here

Phani Kumar M
  • 4,564
  • 1
  • 14
  • 26
pere plop
  • 51
  • 1
  • 10
0

try

 MediaRecorder.AudioSource.VOICE_COMMUNICATION

and see

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

user8256287
  • 177
  • 15