Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-native-call-detection not working in android 10 & 11 #90

Open
asepjumadi opened this issue May 5, 2021 · 2 comments
Open

react-native-call-detection not working in android 10 & 11 #90

asepjumadi opened this issue May 5, 2021 · 2 comments

Comments

@asepjumadi
Copy link

asepjumadi commented May 5, 2021

I test using hook react native 0.64.0 work in android 8.1 but not working in android 10 and 11
permission already be declared in manifest like

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
source code like this:

const startListenerTapped=()=> {
            const callDetector = new CallDetectorManager((event, phoneNumber)=> {
        // For iOS event will be either "Connected",
        // "Disconnected","Dialing" and "Incoming"
     
        // For Android event will be either "Offhook",
        // "Disconnected", "Incoming" or "Missed"
        // phoneNumber should store caller/called number
     console.log(event,'my event on duty')
     
        if (event === 'Disconnected') {

        // Do something call got disconnected
        }
        else if (event === 'Connected') {
        // Do something call got connected
        // This clause will only be executed for iOS
        }
        else if (event === 'Incoming') {
            console.log(event,'my event of hooks')
            console.log(phoneNumber,'my phone number of the day')
            setCodeOtp(phoneNumber.substr(phoneNumber.length-4))
        // Do something call got incoming
        }
        else if (event === 'Dialing') {
        // Do something call got dialing
        // This clause will only be executed for iOS
        }
        else if (event === 'Offhook') {
            console.log(event,'my event of hooks')
            console.log(phoneNumber,'my phone number of the day')
            setCodeOtp(phoneNumber.substr(phoneNumber.length-4))
        //Device call state: Off-hook.
        // At least one call exists that is dialing,
        // active, or on hold,
        // and no calls are ringing or waiting.
        // This clause will only be executed for Android
        }
        else if (event === 'Missed') {
            console.log(event,'my event of hooks')
            console.log(phoneNumber,'my phone number of the day')
            setCodeOtp(phoneNumber.substr(phoneNumber.length-4))
            // Do something call got missed
            // This clause will only be executed for Android
      }
        },
        true, // if you want to read the phone number of the incoming call [ANDROID], otherwise false
        ()=>{}, // callback if your permission got denied [ANDROID] [only if you want to read incoming number] default: console.error
            {
            title: 'Phone State Permission',
            message: 'This app needs access to your phone state in order to react and/or to adapt to incoming calls.'
            } // a custom permission request message to explain to your user, why you need the permission [recommended] - this is the default one
        )
       return callDetector
    }

useEffect(() => {
startReadSMS();
startListenerTapped();
console.log(sms,'my sms on duty')
return ()=>{
//ReadSms.stopReadSMS();
}
},[sms])

@jerry-inc
Copy link

I have figured that you need the following permissions for it to work

<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.READ_CALL_LOG"/> <---- this one is required to get phone number

@zoobibackups
Copy link

zoobibackups commented Feb 16, 2022

I have figured that you need the following permissions for it to work

<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.READ_CALL_LOG"/> <---- this one is required to get phone number

Does this work when app is in background or a foreground service is required to keep the app live????
Without making the app as default dialer call logs permission is a big issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants