android - 如何将带有invokeMethod的字符串数组从Native传递到flutter
问题描述
基于此线程 ,我想将字符串数组作为参数传递,如下所示:
Object obj = new String[] {"Hello","Bye"};
channel.invokeMethod("foo",obj, new MethodChannel.Result(){
...
);
但它显示错误:
不支持的值:[Ljava.lang.String 。
我怎样才能做到这一点?
解决方案
StandardMessageCodec
不支持数组(andint
除外byte
)。对于对象,它支持 Java 集合,例如List
和Map
. 将您的 String 数组更改为List<String>
.
ArrayList<String> args = new ArrayList<>();
args.add("Hello");
args.add("Bye");
channel.invokeMethod("foo", args, new MethodChannel.Result(){
推荐阅读
- java - API 29 中的 AndroidStudio getExternalStoragePublicDirectory
- gatsby - Gatsby - 在构建期间运行函数
- python-3.x - `没有名为'urllib2'的模块-我如何在Python中使用它,以便我可以提出请求
- visual-studio - Visual Studio:如何在编辑器中重新添加代码栏?
- python - 我是否能够将目录路径转换为可以输入 python hdf5 数据表的内容?
- figma-api - Figma 不加载 .fig 文件
- django-rest-framework - 如何在Django rest框架中获取外键的名称
- javascript - 使用 Angular 从 Firestore 数据库返回多个集合
- javascript - 如何使用 javascript 进行搜索和过滤
- kotlin - 如何按 Arraylist 多维分组