CallRecorder icon indicating copy to clipboard operation
CallRecorder copied to clipboard

Not working for Android 10

Open vikash159 opened this issue 5 years ago • 33 comments

audio recorded but no sound

vikash159 avatar Apr 22 '20 20:04 vikash159

@aykuttasil any update on this issue?

AbdulRehmanNazar avatar May 10 '20 06:05 AbdulRehmanNazar

i solved this issue by enabling accessibility service and used VOICE_RECOGNITION. quality is good only on one side. other side its bit low sound. because it using mic

vikash159 avatar May 13 '20 09:05 vikash159

@vikash159 can you please share the working code with us?

AbdulRehmanNazar avatar May 14 '20 10:05 AbdulRehmanNazar

 int source = MediaRecorder.AudioSource.VOICE_COMMUNICATION;
        if (Build.VERSION.SDK_INT >= 29) source = MediaRecorder.AudioSource.VOICE_RECOGNITION;
        mCallRecord = new CallRecord.Builder(this)
                .setRecordFileName("Record")
                .setRecordDirName("mobile")
                .setRecordDirPath(Environment.getExternalStorageDirectory().getAbsolutePath())
                .setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB)
                .setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
                .setAudioSource(source)
                .setLogEnable(true)
                .setShowSeed(true)
                .setShowPhoneNumber(true)
                .build();
import android.accessibilityservice.AccessibilityService;
public class ServiceAccessibility extends AccessibilityService {


    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
    }

    @Override
    public void onInterrupt() {
    }

    @Override
    protected void onServiceConnected() {
        super.onServiceConnected();
    }
}
<service
            android:name=".util.ServiceAccessibility"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
            <intent-filter android:priority="1000">
                <action android:name="android.accessibilityservice.AccessibilityService" />
            </intent-filter>

            <meta-data
                android:name="android.accessibilityservice"
                android:resource="@xml/accessibility_service_config" />
</service>

res/xml

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackAllMask"
    android:accessibilityFlags="flagRetrieveInteractiveWindows|flagReportViewIds|flagIncludeNotImportantViews"
    android:canRequestFilterKeyEvents="false"
    android:canRetrieveWindowContent="true"
    android:description="@string/accessibility_service_description"
    android:notificationTimeout="100"
    android:packageNames="com.securein" />

permissions

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CALL_PHONE" />

vikash159 avatar May 14 '20 16:05 vikash159

Thanks you @vikash159 for your code and comments, do you have to make any changes on the lib side code as well or its working with the above changes only?

AbdulRehmanNazar avatar May 15 '20 05:05 AbdulRehmanNazar

nothing just audio source i have changed. this is not a permanent fix i guess. im still looking for permanent fix because audio captured using mic

vikash159 avatar May 15 '20 07:05 vikash159

Thanks @vikash159 for your comments, I am going to implement and once I will find solution will let you know for sure

AbdulRehmanNazar avatar May 15 '20 08:05 AbdulRehmanNazar

@vikash159 Hello,budy. I have a question for the recorder file. I can not find it in the path . have you got those question?!

A0shashen00 avatar May 21 '20 13:05 A0shashen00

@A0shashen00 try to change path to cache data then it will work

AbdulRehmanNazar avatar May 22 '20 16:05 AbdulRehmanNazar

@A0shashen00 add this line in manifest application tag if you want to save in storage directory instead of cache directory android:requestLegacyExternalStorage="true"

vikash159 avatar May 23 '20 07:05 vikash159

@AbdulRehmanNazar Bhai did it work? if yes can you share the code?

umairdexty avatar Jun 02 '20 12:06 umairdexty

@vikash159 @AbdulRehmanNazar Bro have you got any update on this issue? actually i have added this accessibilityService code using this i am able to record calls but in some scenarios only one side voice is audible and in some scenarios both side voice is clearly audible and in some scenarios one side's voice is clear and one side's voice is bit low. so if you have got any fix please let me know.

erpriyesh avatar Sep 12 '20 05:09 erpriyesh

@erpriyesh it happens with some device or even you use earphone. so no full proof solution i got on this. only samsung device i saw this working properly,

vikash159 avatar Sep 12 '20 13:09 vikash159

@vikash159 @AbdulRehmanNazar Bro have you got any update on this issue? actually i have added this accessibilityService code using this i am able to record calls but in some scenarios only one side voice is audible and in some scenarios both side voice is clearly audible and in some scenarios one side's voice is clear and one side's voice is bit low. so if you have got any fix please let me know.

@erpriyesh can you please share the piece of code with the class which you had implemented...

kishorekmr61 avatar Oct 23 '20 18:10 kishorekmr61

i solved this issue by enabling accessibility service and used VOICE_RECOGNITION. quality is good only on one side. other side its bit low sound. because it using mic

@vikash159 Can you please share the working code.

kishorekmr61 avatar Oct 23 '20 18:10 kishorekmr61

Thanks @vikash159 for your comments, I am going to implement and once I will find solution will let you know for sure

@AbdulRehmanNazar did you got the recorder output file in android 10 I had tried using but I didn't succeed..., it would be great if you share the class file...

kishorekmr61 avatar Oct 23 '20 18:10 kishorekmr61

@vikash159 hey bro i have tested this in another phone. even after enabling the accessibility service call's voice is silence in recording. and now facing this issue in android 9 also can anyone help me ? @AbdulRehmanNazar

erpriyesh avatar Nov 19 '20 13:11 erpriyesh

@erpriyesh it works on some device not on all.

AbdulRehmanNazar avatar Nov 19 '20 14:11 AbdulRehmanNazar

@AbdulRehmanNazar have you got any workaround to overcome from this issue ?

erpriyesh avatar Nov 19 '20 14:11 erpriyesh

@AbdulRehmanNazar @vikash159 hello friends did you find solution for 10 & 11 versions .If you find please let me know thanks

hareesh145 avatar Feb 25 '21 02:02 hareesh145

i have tried this code so far to achieve the call recording but voice is too low of the person we are talking too. further more you have to put this code in accessibility service

` final int BITS_PER_SAMPLE = 8; // 16-bit data final int NUMBER_CHANNELS = 1; // Mono final int COMPRESSION_AMOUNT = 8; // Compress the audio at 8:1

    int sampleRate = 8000;
    final int uncompressedBitRate = sampleRate * BITS_PER_SAMPLE * NUMBER_CHANNELS;

    final int encodedBitRate = uncompressedBitRate  / COMPRESSION_AMOUNT;
    Log.d(TAG, "startRecordingB: encoded bit rate : "+ encodedBitRate);
    recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
    recorder.setOutputFile(getFilename());
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setAudioChannels(1);
    recorder.setAudioSamplingRate(8000);
    recorder.setAudioEncodingBitRate(encodedBitRate);`

TravelChannel avatar Mar 25 '21 11:03 TravelChannel

@vikash159 about the accessibilty service uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" this permission is only allowed for system apps how did you handle that? and i will appreciate it if you share the complete code i have difficulties implementing accessibility service for android 10.

MasterKali06 avatar Jun 19 '21 08:06 MasterKali06

@MasterKali06 You can't "start" the AccessibilityService as they are not like other services where you can control their start/stop. Rather here the Android system controls starting and stopping them based on the settings the user has selected.

The best you can do is launch the Accessibility settings page and get the user to enable it for you:

Intent openSettings = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); openSettings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(openSettings);

vikash159 avatar Jun 19 '21 14:06 vikash159

@vikash159 @MasterKali06 @hareesh145 @AbdulRehmanNazar @kishorekmr61 @umairdexty can any of you please share your working call recorder app repository here please, because I am searching the internet for 1 week and this is the best lead I got so far. I am badly stuck in the installation process of this package. and I cannot move further in this. I urgently need to build a call recorder app in android. Thank You

Vinayak-Bhardwaj avatar Dec 20 '21 14:12 Vinayak-Bhardwaj

@Vinayak-Bhardwaj As I know you can't record calls from both side anymore, that is the restriction added for new Android OS

https://nllapps.com/apps/acr/android9.htm

developer-- avatar Dec 20 '21 14:12 developer--

Thanks for the response @developer-- , but the above discussion shows that maybe it is possible on android 10. And on the play store as well there exist applications that record calls from both sides. So can you help me with that, please?

Vinayak-Bhardwaj avatar Dec 20 '21 15:12 Vinayak-Bhardwaj

can you confirm that they are recording voice from both side with good quality? I think all apps were affected

developer-- avatar Dec 20 '21 15:12 developer--

yes @developer-- , I have myself tested it. On using earphones while talking we can hear clear voices from both ends. If you want then I can share you the link for the application

Vinayak-Bhardwaj avatar Dec 20 '21 15:12 Vinayak-Bhardwaj

@Vinayak-Bhardwaj can you please share your code of call recording if possible please?

Shubham-Narkhede avatar Jan 27 '22 12:01 Shubham-Narkhede

 int source = MediaRecorder.AudioSource.VOICE_COMMUNICATION;
        if (Build.VERSION.SDK_INT >= 29) source = MediaRecorder.AudioSource.VOICE_RECOGNITION;
        mCallRecord = new CallRecord.Builder(this)
                .setRecordFileName("Record")
                .setRecordDirName("mobile")
                .setRecordDirPath(Environment.getExternalStorageDirectory().getAbsolutePath())
                .setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB)
                .setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
                .setAudioSource(source)
                .setLogEnable(true)
                .setShowSeed(true)
                .setShowPhoneNumber(true)
                .build();
import android.accessibilityservice.AccessibilityService;
public class ServiceAccessibility extends AccessibilityService {


    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
    }

    @Override
    public void onInterrupt() {
    }

    @Override
    protected void onServiceConnected() {
        super.onServiceConnected();
    }
}
<service
            android:name=".util.ServiceAccessibility"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
            <intent-filter android:priority="1000">
                <action android:name="android.accessibilityservice.AccessibilityService" />
            </intent-filter>

            <meta-data
                android:name="android.accessibilityservice"
                android:resource="@xml/accessibility_service_config" />
</service>

res/xml

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes="typeAllMask"
    android:accessibilityFeedbackType="feedbackAllMask"
    android:accessibilityFlags="flagRetrieveInteractiveWindows|flagReportViewIds|flagIncludeNotImportantViews"
    android:canRequestFilterKeyEvents="false"
    android:canRetrieveWindowContent="true"
    android:description="@string/accessibility_service_description"
    android:notificationTimeout="100"
    android:packageNames="com.securein" />

permissions

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CALL_PHONE" />

Hi @vikash159 How to connect recorder codes to AccessibilityService codes? Please send the source code

amoozesh3 avatar Feb 27 '22 20:02 amoozesh3