- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在添加创建我自己的平台 channel (具体来说,Android 的方法 channel )并关注 https://flutter.io/docs/development/platform-integration/platform-channels#step-1-create-a-new-app-project
我明白了:
All channel names used in a single app must be unique; we recommend prefixing the channel name with a unique ‘domain prefix’, e.g. samples.flutter.io/battery.
名称是否需要特定格式?例如。我可以将我的 channel 命名为简单的 ol' battery
吗?或者它有一些围绕格式 my_company.flutter.io/battery
的东西吗?或者是其他东西?我尝试了各种字符串,但每次我都得到:
MissingPluginException(未在 channel 电池上找到方法 getBattery 的实现)
所以我想知道是不是我的 channel 名称格式不正确。我认为我的方法名称 getBattery 是正确的。但要澄清的是,我想做的是:
final result = await platform.invokeMethod('getBattery');
没有插件前缀,对吧?
final result = await platform.invokeMethod('battery.getBattery');
最佳答案
我有一个实例 here我以前做过几次。
Does the name need to be a specific format? E.g. Can I name my channel just plain ol' battery? Or does it have be something around the format my_company.flutter.io/battery? Or something else?
由于 channel 名称必须是唯一的,因此最好在其前面加上您的 bundle(iOS)/package(Android) id
。
例如:
static const platform =
const MethodChannel('it.versionestabile.flutterapp000001/pdfViewer');
无论如何,您可以随意调用它,但它应该是独一无二的,并且在您的 Dart 和 Android/iOS 方面是平等的。
private static final String CHANNEL = "it.versionestabile.flutterapp000001/pdfViewer";
但是“调用”它就像放入 channel 中一样。
因为 channel 是一个 channel (想象一个管道),你把它放在里面从一边(Dart)传递到另一个(Android/iOS)完全是另一个故事^ _^。
你放在里面的东西,应该从另一边被捕获。
platform.invokeMethod('viewPdf', args);
因此,您通过 channel 发送的只是消息。
你在 pipe 里放了一个带有字母的瓶子^_^
现在您必须在您的 native 代码端捕获此消息,例如 'viewPdf'
。
new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.equals("viewPdf")) {
if (call.hasArgument("url")) {
String url = call.argument("url");
File file = new File(url);
//*
Uri photoURI = FileProvider.getUriForFile(MainActivity.this,
BuildConfig.APPLICATION_ID + ".provider",
file);
//*/
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(photoURI,"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
target.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(target);
result.success(null);
}
} else {
result.notImplemented();
}
}
});
}
否则你会陷入困境
} else {
result.notImplemented();
}
如果您遵循示例,您应该在您的 Android native 代码端拥有此示例:
@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("getBatteryLevel")) {
int batteryLevel = getBatteryLevel();
if (batteryLevel != -1) {
result.success(batteryLevel);
} else {
result.error("UNAVAILABLE", "Battery level not available.", null);
}
} else {
result.notImplemented();
}
}
所以你应该调用:
platform.invokeMethod('getBatteryLevel');
因为该示例的代码需要通过 channel 传递消息 'getBatteryLevel'
。
强化概念
因此,为了强化所有这些概念,我将进一步告诉您,您可以决定使用 channel 来服务于单个操作或服务于多个操作。选择权在您。
所以你可以
飞镖方面:
static const singleChannel =
const MethodChannel('it.versionestabile.flutterapp000001/single');
static const multiChannel =
const MethodChannel('it.versionestabile.flutterapp000001/multi');
native 端 (Android):
private static final String SINGLE_CHANNEL = "it.versionestabile.flutterapp000001/single";
private static final String MULTI_CHANNEL = "it.versionestabile.flutterapp000001/multi";
还有一些玩具搬运工:
new MethodChannel(getFlutterView(), MULTI_CHANNEL).setMethodCallHandler(
new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.equals("op1")) {
new AlertDialog.Builder(MainActivity.this)
.setTitle(call.method)
.setMessage("I'm the " + call.method + " of the by design multi operation channel!")
.create()
.show();
} else if (call.method.equals("op2")) {
new AlertDialog.Builder(MainActivity.this)
.setTitle(call.method)
.setMessage("I'm the " + call.method + " of the by design multi operation channel!")
.create()
.show();
} else {
result.notImplemented();
}
}
});
new MethodChannel(getFlutterView(), SINGLE_CHANNEL).setMethodCallHandler(
new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.equals("hello")) {
new AlertDialog.Builder(MainActivity.this)
.setTitle("hello!")
.setMessage("I'm the by design single operation channel!")
.create()
.show();
} else {
result.notImplemented();
}
}
});
void _invokeMultiChannelOp2() {
multiChannel.invokeMethod('op2');
}
void _invokeMultiChannelOp1() {
multiChannel.invokeMethod('op1');
}
void _invokeSingleChannel() {
singleChannel.invokeMethod('hello');
}
floatingActionButton: SafeArea(
child: Padding(
padding: EdgeInsets.only(left: 8.0),
child: Row(
children: <Widget>[
new IconButton(
icon: new Icon(Icons.library_music),
onPressed: _invokeMultiChannelOp1),
new IconButton(
icon: new Icon(Icons.note),
onPressed: _invokeMultiChannelOp2),
new IconButton(
icon: new Icon(Icons.plus_one),
onPressed: _invokeSingleChannel),
],
)),
),
关于android - Flutter 平台 channel 的 channel 名称应该是什么格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53888502/
我在 cordova@7.1.0、cordova-ios@4.5.2 下运行。安装平台:ios 4.5.2。 我运行 npm install、bower install,然后运行 cordova
我正在使用 VSTS 构建 IOS,运行命令后出现以下错误:cordova build ios 平台“android”似乎不是有效的 cordova 平台。它缺少 API.js。不支持安卓。 Cord
您使用什么软件/Wiki 来编写和分享有关开发人员、测试人员和管理人员的规范? 你使用维基系统,如果是,你使用什么维基软件? 或者您是否使用 Sharepoint 来管理和版本规范?将 SharePo
这是一家销售完整软件套件/平台的公司的示例 www.ql2.com/technology/platform.php 我想知道这样的套件/平台是如何开发的?你必须使用J2EE吗? 我更感兴趣的是这家公司
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我有一个连接到套接字连接的应用程序,并且该连接向我发送了很多信息..可以说每秒 300 个订单(也许更多)..我有一个类(它就像一个监听器,对某个事件(并且该事件具有顺序)接收该顺序。创建一个对象,然
我即将开始一个 Netbeans 平台的项目。有没有人推荐他们用过并觉得有用的书籍或教程? 编辑: 这是一个已经开发好的swing应用。 最佳答案 除了 NetBeans 网站上的教程外,我还喜欢这本
有没有什么好的方法可以以非特定语言的方式定义接口(interface)/类层次结构,然后以特定语言生成相应的源代码?特别是,我需要同时针对 Java 和 C# 来创建一个相当全面的 API。我记得有一
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
大家晚上好我使用 API 平台,我想在创建实体时自动将所有者添加到我的实体中。我创建了一个事件来覆盖 API 平台,它获取当前用户并添加它。但是我的事件永远不会发生,但它确实存在于 debug:eve
这是一个有点奇怪的元编程问题,但我意识到我的新项目不需要完整的 MVC 框架,作为一个 Rails 人,我不确定现在该使用什么。 为您提供必要功能的要点;该网站将显示静态页面,但用户将能够登录并“编辑
这两天我的信息有点过载。 我打算建立自己的网站,允许本地企业列出他们的打折商品,然后用户可以进来搜索“Abercrombie T 恤”,然后就会列出出售它们的商店。 这是一个非常棒的小项目,我真的很兴
我的任务是为产品的下一代版本评估“企业”平台。我们目前正在考虑两种“类型”的平台——RAD(工作流引擎、集成 UI、工作流“技术插件”的小核心、状态的自动持久化……),例如 SalesForce.co
我需要一个不依赖于特定语言或构建系统的依赖管理器。我研究了几个优秀的工具(Gradle、Bazel、Hunter、Biicode、Conan 等),但没有一个能满足我的要求(见下文)。我还使用了 Gi
我在 Symfony 4 Flex 应用程序中使用 API Platform v2.2.5,该应用程序由一个功能 API 和 JWT Authentication 组成。 ,一些资源默认Open AP
虽然隐私法通常不属于我们开发人员的管辖范围,但我确实认为这是一个重要的话题,因为我们开发人员应该有责任警告我们的雇主,如果他们想要的东西会违反一些法律......在这种情况下,隐私法......通常情
我已经下载了 VisualVM 源代码,并尝试使用 Netbeans 7.01 编译 Glassfish 插件。这样做会导致以下错误: C:\source\visualvm\trunk\plugins
尝试 gradle 同步后...失败并在消息对话框中显示 Missing Android platform(s) detected: 'android-26' Install missing plat
大家好!我最近开始使用 Cordova,当我运行 Cordova platform add android 时,出现以下错误。我已经成功放置了 Java 和 Android SDK 的环境变量。但 n
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
我是一名优秀的程序员,十分优秀!