我正在尝试从android MainActivity类启动上下文到flutter。代码:
val authResult = ComponentActivity().registerForActivityResult(PianoIdAuthResultContract()) { r ->
when (r) {
null -> { /* user cancelled Authorization process */ }
is PianoIdAuthSuccessResult -> {
val token = r.token
val isNewUserRegistered = r.isNewUser
if (token != null) {
if (token.emailConfirmationRequired) {
// process enabled Double opt-in
}
}
// process successful authorization
}
is PianoIdAuthFailureResult -> {
val e = r.exception
// Authorization failed, check e.cause for details
}
}
}
然后调用方法启动代码:
try{
authResult.launch(PianoId.signIn());
}catch (e : Exception){
val text = e.message
val duration = Toast.LENGTH_SHORT
val toast = Toast.makeText(applicationContext, text, duration)
toast.show()
}
然后通过在Flutter和android之间创建一个通道并调用它来从Flutter中调用此方法:
signInChannel.invokeMethod('testSignIn');
当我按下登录按钮时,它显示此异常:
尝试在空对象引用上调用虚拟方法“android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()”
1条答案
按热度按时间dsekswqp1#
我也在寻找解决方案。我所做的是用FlutterFragmentActivity扩展MainActivity,并将 this 传递给方法通道处理程序。
成功了