Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getCurrentActivity is not public 'com.facebook.react.bridge.React Context` cannot be accessed from outside package

I'm trying to build react-native module that require pass the Activity to some method

private ReactApplicationContext reactContext;

...

@ReactMethod
public void sendVerificationCode(String phoneNumber)
{
    PhoneAuthProvider.getInstance().verifyPhoneNumber(
            phoneNumber,                            // Phone number to verify
            60,                                     // Timeout duration
            TimeUnit.SECONDS,                       // Unit of timeout
            reactContext.getCurrentActivity(),      // Activity (for callback binding)
            callback);                              // OnVerificationStateChangedCallbacks

}

I used reactContext.getCurrentActivity() to get the current activity from but it tells me that getCurrentActivity() is not public and cannot be accessed from outside package

getCurrentActivity is not public 'com.facebook.react.bridge.React Context` cannot be accessed from outside package

how could I get the current activity ?

full code :

public class FirebasePhoneAuth extends ReactContextBaseJavaModule
{
    private ReactApplicationContext reactContext;
    private OnVerificationStateChanged callback;

    public FirebasePhoneAuth(ReactApplicationContext reactContext)
    {
        super(reactContext);
        this.reactContext = reactContext;
    }

    @Override
    public String getName()
    {
        return "FirebasePhoneAuth";
    }

    @ReactMethod
    public void sendVerificationCode(String phoneNumber)
    {
        PhoneAuthProvider.getInstance().verifyPhoneNumber(
                phoneNumber,                            // Phone number to verify
                60,                                     // Timeout duration
                TimeUnit.SECONDS,                       // Unit of timeout
                reactContext.getCurrentActivity(),      // Activity (for callback binding)
                callback);                              // OnVerificationStateChangedCallbacks

    }

}
like image 880
Ali Faris Avatar asked Aug 23 '17 08:08

Ali Faris


1 Answers

the class ReactContextBaseJavaModule already have method getCurrentActivity()

code :

public class FirebasePhoneAuth extends ReactContextBaseJavaModule
{
    ...

    @ReactMethod
    public void sendVerificationCode(String phoneNumber)
    {
        Activity activity = getCurrentActivity();

        PhoneAuthProvider.getInstance().verifyPhoneNumber(
                phoneNumber,
                60,
                TimeUnit.SECONDS,                      
                activity,
                callback);

    }

}
like image 100
Ali Faris Avatar answered Nov 10 '22 19:11

Ali Faris