aykuttasil / CallRecorder

Android Phone Call Recorder
MIT License
757 stars 239 forks source link

Not working for Android 10 #51

Open vikash159 opened 4 years ago

vikash159 commented 4 years ago

audio recorded but no sound

AbdulRehmanNazar commented 4 years ago

@aykuttasil any update on this issue?

vikash159 commented 4 years ago

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

AbdulRehmanNazar commented 4 years ago

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

vikash159 commented 4 years ago
 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" />
AbdulRehmanNazar commented 4 years ago

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?

vikash159 commented 4 years ago

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

AbdulRehmanNazar commented 4 years ago

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

A0shashen00 commented 4 years ago

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

AbdulRehmanNazar commented 4 years ago

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

vikash159 commented 4 years ago

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

umairdexty commented 4 years ago

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

erpriyesh commented 4 years ago

@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.

vikash159 commented 4 years ago

@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,

kishorekmr61 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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...

erpriyesh commented 3 years ago

@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

AbdulRehmanNazar commented 3 years ago

@erpriyesh it works on some device not on all.

erpriyesh commented 3 years ago

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

hareesh145 commented 3 years ago

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

TravelChannel commented 3 years ago

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);`
MasterKali06 commented 3 years ago

@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.

vikash159 commented 3 years ago

@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);

Vinayak-Bhardwaj commented 2 years ago

@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

developer-- commented 2 years ago

@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

Vinayak-Bhardwaj commented 2 years ago

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?

developer-- commented 2 years ago

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

Vinayak-Bhardwaj commented 2 years ago

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

Shubham-Narkhede commented 2 years ago

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

amoozesh3 commented 2 years ago
 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

ashishpatel16 commented 2 years ago

Any updates on android 10 so far?

cmedamine commented 2 years ago

is there any hack for this issue yet?, or if there is any other solution other than MediaRecorder() object

DidarSeyidov commented 1 year ago

How can I create a custom call recorder for Android Q like ACR Phone Helper?