1

I can only record my voice from this code, not against the turns.

And I used MediaRecorder.AudioSource.VOICE_CALL instead of MediaRecorder.AudioSource.MIC

But still I am getting my voice only.

Here is my code

public class RecorderService extends IntentService {

    private Context mContext;
    private MediaRecorder recorder;
    static final String TAGS = "RecorderService";

    private String phoneNumber;

    public RecorderService() {
        super("RecorderService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
    }

    @Override
    public int onStartCommand(@Nullable Intent intent, int flags, int startId) {
        Log.e(TAGS, "Started!");
        mContext = getApplicationContext();

        phoneNumber = intent.getStringExtra("number");
        Log.e(TAGS, "Calling Number : " + phoneNumber);

        recorder = new MediaRecorder();
        startRecording();

        return START_NOT_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.e(TAGS, "Stopped!");
        stopRecording();
    }

    private void startRecording() {
        Log.e(TAGS, "Recording Started");

        File file = new File(Environment.getExternalStorageDirectory()
                + File.separator
                + "My Records"
                + File.separator);

        recorder.reset();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        recorder.setOutputFile(file.getAbsolutePath() + "record.mp3");

        try {
            recorder.prepare();
        } catch (IOException e) {
            e.printStackTrace();
        }
        recorder.start();
    }

    private void stopRecording() {
        Log.e(TAGS, "Recording Stopped");
        if (recorder != null) {
            recorder.stop();
            recorder.reset();
            recorder.release();
            recorder = null;
        }
    }
}

Any suggestions!

Dinesh Shingadiya
  • 988
  • 1
  • 8
  • 23
  • Hi Dinesh, welcome to Stack Overflow! Please edit your post so that it [only contains code relevant to the problem](https://stackoverflow.com/help/mcve). This will make it easier for someone to answer your question. –  Apr 27 '19 at 06:01
  • Your question is not relevant to your problem – Vignesh Apr 27 '19 at 06:44

1 Answers1

1

You can't. Not unless you're a system app (which you need to be installing your own custom OS or be root to get). VOICE_CALL requires the CAPTURE_AUDIO_OUTPUT permission which is a system permission- normal apps can't use it.

How do the other apps on the Play store do it? They use the mic, and hope the output of the call is loud enough to pick it up.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127