gpt4 book ai didi

android - getCurrentActivity 不是公开的 'com.facebook.react.bridge.React Context` 无法从外部包访问

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:14:29 26 4
gpt4 key购买 nike

我正在尝试构建 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()不是公开的,不能从外部包访问

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

如何获取当前 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);

}

}

关于android - getCurrentActivity 不是公开的 'com.facebook.react.bridge.React Context` 无法从外部包访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45834070/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com