0

I have used this code, working for android 5.1(MotoE and MotoX and 1 more device) and 8.1.0(Nokia 6) But not working for 8.0(One Plus 5) and 7.0(MotoG5).

        new Thread(new Runnable() {
            @Override
            public void run() {

                try {

                    recorder = new MediaRecorder();

                    recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
                    recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
                    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                    //recorder.setAudioEncodingBitRate(320000);
                    //recorder.setAudioSamplingRate(44100);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                File sampleDir = new File(Environment.getExternalStorageDirectory(), "/AutoCallPicker/PhoneCallRecord/");
                if (!sampleDir.exists()) {
                    sampleDir.mkdirs();
                }
                //String file_name = "Record";
                String file_name = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());//Naming according to date and time
                try {
                    audioFile = File.createTempFile(file_name, ".amr",
                            sampleDir);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                //Set output file .
                recorder.setOutputFile(audioFile.getAbsolutePath());
                //String formattedMessage[] = audioFile.getAbsolutePath().split(Commands.SPLIT_BY_SLASH);
                //fileNameRecordedCall = formattedMessage[formattedMessage.length - 1].toString();
                try {
                    //Call prepare before start().
                    recorder.prepare();
                    //Start recording .
                    recorder.start();
                    recordStarted = true;
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

permissions given

     <!-- Calling permission -->
<uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- permission to write on external storage -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

I have also used Device Policy Manager and made my device admin as mentioned in accepted answer of below link How to record phone calls in android?

but this thing is not working for any device.Please help what setting I am missing.

Naveen Mahaur
  • 81
  • 1
  • 2
  • 5

0 Answers0