小编Mah*_*Bkh的帖子

升级flutter后创建方法通道-无法解析方法getFlutterView()

我在我的颤振应用程序中使用本机 android 方法使用说明使用的文档

MethodChannel(flutterView, CHANNEL).setMethodCallHandler...
Run Code Online (Sandbox Code Playgroud)

但是在升级 flutter 之后,该MethodChannel功能不需要了flutterView,也没有flutterView了。

can not resolve method getFlutterView()
Run Code Online (Sandbox Code Playgroud)

我认为应该有一个创建频道的新教程

相反,它需要一些BinaryMessenger我不知道该给什么的。

这是不再工作的旧代码:

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;

public class MainActivity extends FlutterActivity {
private static final String CHANNEL = "samples.flutter.dev/battery";

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    GeneratedPluginRegistrant.registerWith(this);

    new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
            new MethodCallHandler() {
                @Override
                public void onMethodCall(MethodCall call, Result result) {
                    // Note: this method is invoked on the main thread.
                    // …
Run Code Online (Sandbox Code Playgroud)

android flutter flutter-channel

16
推荐指数
2
解决办法
7511
查看次数

如何为flutter应用程序添加android通知通道ID以在应用程序处于后台时修复通知

在我的 flutter 应用程序中,onResume 和 onLunch 函数在 android 平台上不起作用,虽然它们在 IOS 上运行良好,但我在控制台上收到以下消息,而不是在这些函数中打印字符串:

“W/FirebaseMessaging(24847):AndroidManifest 中缺少默认通知通道元数据。将使用默认值。”

onMessage 功能工作正常,问题是应用程序在后台时

我的猜测是它与应该添加到 android manifest 中的 android 通知通道 id 有关

当我通过将以下代码添加到 AndroidManifest 将其添加到清单时,消息更改为 :(我在值中添加了一个 strings.xml 文件并在那里定义了“default_notification_channel_id”。)

“应用程序尚未创建 AndroidManifest.xml 中设置的通知通道。将使用默认值。”

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id"/>
Run Code Online (Sandbox Code Playgroud)

在我的控制台中,我应该收到我打印的 onResume 和 onLunch 字符串,但我收到以下消息:

“W/FirebaseMessaging(24847):AndroidManifest 中缺少默认通知通道元数据。将使用默认值。”

“应用程序尚未创建 AndroidManifest.xml 中设置的通知通道。将使用默认值。”

<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id"/>
Run Code Online (Sandbox Code Playgroud)

android-notifications flutter firebase-cloud-messaging

10
推荐指数
2
解决办法
8460
查看次数