我正在尝试构建react-native模块,该模块需要将Activity传递给某些方法

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

}

我使用reactContext.getCurrentActivity()从中获取当前 Activity ,但它告诉我getCurrentActivity()不是公共(public)的,无法从外部程序包进行访问



我如何获得当前 Activity ?

完整代码:
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

    }

}

最佳答案

该类ReactContextBaseJavaModule已经具有方法getCurrentActivity()
代码 :

public class FirebasePhoneAuth extends ReactContextBaseJavaModule
{
    ...

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

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

    }

}

09-25 22:14