androidreact-nativecomponentsandroid-phone-call

react-native-immediate-phone-call not working


I am writing app that uses react-native-immediate-phone-call and by pressing Pressable component I need to call function from that module.

import RNImmediatePhoneCall from 'react-native-immediate-phone-call';

export default function App() {
    const [getNumber, setNumber] = useState('');

    function makeCall() {
        console.log('dialing');
        return () => RNImmediatePhoneCall.immediatePhoneCall(getNumber);
    }
    ...
    return (
        ...
        <Pressable onPress={()=>makeCall()}>
            <Image source={require('./assets/phone-call.png')}/>
        </Pressable>
        ...
    );
}

Console log is displayed into terminal with Metro Bunler but return does not execute somehow. I am newbie into js and react. How function and function call should like?


Solution

  • At that moment getNumber == ''

    So, I think RNImmediatePhoneCall.immediatePhoneCall('') do nothing.

    Also, try with this (will be work when getNumber has a value)

    function makeCall() {
        console.log('dialing');
        RNImmediatePhoneCall.immediatePhoneCall(getNumber);
    }
    

    EDIT:

    Still, nothing happens, I find a solution from their issues

    First, check your phone permission for call: In the AndroidManifest.xml Then add the following lines

    <uses-permission android:name="android.permission.CALL_PHONE" />
    

    If still not working, do follow the steps

    In settings.gradle after rootProject.name = 'YOUR_PROJ_NAME' add the following line

    include ':react-native-immediate-phone-call', ':app'
    

    In build.gradle Inside the dependencies section insert the following line

    implementation project(':react-native-immediate-phone-call')
    

    In AndroidManifest.xml add the following line with all other user-permissions

    <uses-permission android:name="android.permission.CALL_PHONE" />
    

    In MainActivity.java import this

    import com.github.wumke.RNImmediatePhoneCall.RNImmediatePhoneCallPackage;
    

    inside the class, MainActivity add the following override (include the "@override" for some reason it's not in the same block with the rest of the code)

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        
        RNImmediatePhoneCallPackage.onRequestPermissionsResult(requestCode, permissions, grantResults); // very important event callback
        
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    
    }