我正在尝试构建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()
来获取当前活动,但它告诉我getCurrentActivity()
不公开,无法从外部包访问
getCurrentActivity不是public' com.facebook.react.bridge.React 无法从外部包中访问Context`
我怎样才能获得当前的活动?
完整代码:
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
}
}
答案 0 :(得分:0)
班级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);
}
}