[英]Flutter:PlatformException(error, Attempt to invoke virtual method 'java.lang.Object android.app.Activity.getSystemService(java.lang.String)'
I am trying to enable my app as admin using this plugin.我正在尝试使用此插件以管理员身份启用我的应用程序。
This is my code below:这是我下面的代码:
@override
void initState() {
super.initState();
Admin.enable();
_callStreamSubscription = phoneStateCallEvent.listen((PhoneStateCallEvent event) {
print('Call is Incoming or Connected: ' + event.stateC);
if(event.stateC=="true"){
_invokeNativeMethod("startRecording");
}
else if(event.stateC=="false"){
_invokeNativeMethod("stopRecording");
}
});
}
Error is as follows:错误如下:
E/flutter ( 8036): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'java.lang.Object android.app.Activity.getSystemService(java.lang.String)' on a null object reference, null)
E/flutter ( 8036): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 8036): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter ( 8036): <asynchronous suspension>
E/flutter ( 8036): #2 Admin.enable (package:admin/admin.dart:10:21)
E/flutter ( 8036): #3 _MyHomePageState.initState (package:automatic_call_recorder/main.dart:55:11)
Any help would really be appreciated!!任何帮助将不胜感激!
So, I got the solution:所以,我得到了解决方案:
Actually, I tried adding the code in my old package where I had platform-specific code in which I had removed this line实际上,我尝试在旧的 package 中添加代码,其中我删除了这一行的平台特定代码
GeneratedPluginRegistrant.registerWith(flutterEngine);
Because of which the error was occuring.因此发生了错误。 So I added the line again and it works fine now.
所以我再次添加了该行,现在它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.