priteshrnandgaonkar / react-native-call-detection

react-native package to detect call states
MIT License
191 stars 110 forks source link

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

Open asepjumadi opened 3 years ago

asepjumadi commented 3 years ago

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])

#

abdullah-aj commented 3 years ago

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

`

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

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.