Android Call Recording Incoming voice not getting recorded

后端 未结 6 833
猫巷女王i
猫巷女王i 2020-12-07 19:09

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 r

相关标签:
6条回答
  • 2020-12-07 19:42

    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?

    0 讨论(0)
  • 2020-12-07 19:43

    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

    0 讨论(0)
  • 2020-12-07 19:43

    try

     MediaRecorder.AudioSource.VOICE_COMMUNICATION
    

    and see

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

    0 讨论(0)
  • 2020-12-07 19:55

    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.

    0 讨论(0)
  • 2020-12-07 20:00

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

    Link

    0 讨论(0)
  • 2020-12-07 20:06

    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.

    0 讨论(0)
提交回复
热议问题