首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >无法将PluginRegistry转换为FlutterEngine

无法将PluginRegistry转换为FlutterEngine
EN

Stack Overflow用户
提问于 2019-12-22 18:20:25
回答 8查看 32.3K关注 0票数 77

当我将flutter更新到1.12.13版本时,我发现了这个问题,并且无法修复它。我按照firebase_messaging教程发送的那样做了,得到了以下错误:“错误:不兼容的类型:无法将PluginRegistry转换为FlutterEngine GeneratedPluginRegistrant.registerWith (注册表);”我的代码如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package io.flutter.plugins;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;

public class Application extends FlutterApplication implements PluginRegistrantCallback {
  @Override
  public void onCreate() {
    super.onCreate();
    FlutterFirebaseMessagingService.setPluginRegistrant(this);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
      NotificationChannel channel = new NotificationChannel("messages","Messages", NotificationManager.IMPORTANCE_LOW);
  NotificationManager manager = getSystemService(NotificationManager.class);
  manager.createNotificationChannel(channel);
    }
  }

  @Override
  public void registerWith(PluginRegistry registry) {
    GeneratedPluginRegistrant.registerWith(registry);
  }
}
EN

回答 8

Stack Overflow用户

发布于 2020-03-31 19:11:19

替换此代码行:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
GeneratedPluginRegistrant.registerWith(registry);

有了这个:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));

确保导入:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
票数 111
EN

Stack Overflow用户

发布于 2019-12-26 16:02:30

更新于2019年12月31日。

您不应该使用Firebase云消息工具来发送通知,因为它会强制您使用标题和正文。

您必须发送不带标题和正文的通知。将应用程序放在后台,这对你来说应该是可行的。

如果它对你有效,如果你能对这个答案给我一票,我将不胜感激,谢谢。

我找到了一个临时的解决方案。我不确定这是不是最好的修复,但是我的插件按预期工作,我假设问题出在io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService在第164行提供的注册表上。

我的AndroidManifest.xml文件:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="Your Package"> // CHANGE THIS

    <application
        android:name=".Application"
        android:label="" // YOUR NAME APP
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        <!-- BEGIN: Firebase Cloud Messaging -->    
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        <!-- END: Firebase Cloud Messaging -->    
        </activity>
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

My Application.java

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package YOUR PACKAGE HERE;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

public class Application extends FlutterApplication implements PluginRegistrantCallback {

  @Override
  public void onCreate() {
    super.onCreate();
    FlutterFirebaseMessagingService.setPluginRegistrant(this);
  }

  @Override
  public void registerWith(PluginRegistry registry) {
    FirebaseCloudMessagingPluginRegistrant.registerWith(registry);
  }
}

My FirebaseCloudMessagingPluginRegistrant.java

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package YOUR PACKAGE HERE;

import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;

public final class FirebaseCloudMessagingPluginRegistrant{
  public static void registerWith(PluginRegistry registry) {
    if (alreadyRegisteredWith(registry)) {
      return;
    }
    FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
  }

  private static boolean alreadyRegisteredWith(PluginRegistry registry) {
    final String key = FirebaseCloudMessagingPluginRegistrant.class.getCanonicalName();
    if (registry.hasPlugin(key)) {
      return true;
    }
    registry.registrarFor(key);
    return false;
  }
}

dart格式的发送通知:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Future<void> sendNotificationOnBackground({
  @required String token,
}) async {
  await firebaseMessaging.requestNotificationPermissions(
    const IosNotificationSettings(sound: true, badge: true, alert: true, provisional: false),
  );
  await Future.delayed(Duration(seconds: 5), () async {
    await http.post(
    'https://fcm.googleapis.com/fcm/send',
     headers: <String, String>{
       'Content-Type': 'application/json',
       'Authorization': 'key=$SERVERTOKEN', // Constant string
     },
     body: jsonEncode(
     <String, dynamic>{
       'notification': <String, dynamic>{

       },
       'priority': 'high',
       'data': <String, dynamic>{
         'click_action': 'FLUTTER_NOTIFICATION_CLICK',
         'id': '1',
         'status': 'done',
         'title': 'title from data',
         'message': 'message from data'
       },
       'to': token
     },
    ),
  );
  });  
}

我添加了一个持续时间为5秒的等待,这样您就可以将应用程序放在后台,并验证后台的消息是否正在运行

票数 36
EN

Stack Overflow用户

发布于 2020-03-04 17:43:27

可以在下面找到DomingoMG代码到Kotlin的端口(包括文件路径)。在10.2020上测试和工作。

/pubspec.yaml

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
firebase_messaging: ^7.0.0

/android/app/src/main/kotlin/Application.kt

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package YOUR_PACKAGE_HERE

import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService

public class Application: FlutterApplication(), PluginRegistrantCallback {
  override fun onCreate() {
    super.onCreate()
    FlutterFirebaseMessagingService.setPluginRegistrant(this)
  }

  override fun registerWith(registry: PluginRegistry) {
    FirebaseCloudMessagingPluginRegistrant.registerWith(registry)
  }
}

/android/app/src/main/kotlin/FirebaseCloudMessagingPluginRegistrant.kt

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package YOUR_PACKAGE_HERE

import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin

class FirebaseCloudMessagingPluginRegistrant {
  companion object {
    fun registerWith(registry: PluginRegistry) {
      if (alreadyRegisteredWith(registry)) {
        return;
      }
      FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
    }

    fun alreadyRegisteredWith(registry: PluginRegistry): Boolean {
      val key = FirebaseCloudMessagingPluginRegistrant::class.java.name
      if (registry.hasPlugin(key)) {
        return true
      }
      registry.registrarFor(key)
      return false
    }
  }
}
票数 29
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59446933

复制
相关文章
在不是Thread类的子类中,如何获取线程对象的名称呢?
我想要获取main方法所在的线程对象的名称,该怎么办呢?   遇到这种情况,Thread类就提供了一个很好玩的方法:     public static Thread currentThread()
黑泽君
2018/10/11
4.9K0
[python]父类、子类、子类实例属性
本文旨在说明 父类、子类、子类实例的属性继承关系: >>> A = type('A', (), {'name':1}) >>> B = type('B',(A,), {'addr':'beijing'})    #B的父类为A >>> A.__dict__ mappingproxy({'name': 1, '__module__': '__main__', '__dict__': <attribute '__dict__' of 'A' objects>, '__weakref__': <attribute
py3study
2020/01/19
1.9K0
在 WPF 中获取一个依赖对象的所有依赖项属性
本来 .NET 中提供了一些专供设计器使用的类型 TypeDescriptor 可以帮助设计器找到一个类型或者组件的所有可以设置的属性,不过我们也可以通过此方法来获取所有可供使用的属性。
walterlv
2023/10/22
4200
java父类引用指向子类对象好处_java子类调用父类属性
Java之所以引入多态的概念,原因之一就它在类的继承上的问题和C++不同,后者允许多继承,这确实给其带来了非常强大的功能,但是复杂的继承关系也给C++开发者带来了更大的麻烦,为了规避风险,Java只允许单继承,势必在功能上有很大的限制,所以,Java引入多态性的概念以弥补这点不足,此外,抽象类和接口也是解决单继承规定限制的重要手段.同时,多态也是面向对象编程的精髓所在.
全栈程序员站长
2022/11/03
1.3K0
Fabric.js 保存自定义属性
但从上图可以看出,创建 矩形rect 时自定义了一个 my_id 的属性,但输出时却看不到 my_id。
德育处主任
2022/10/28
2.9K0
Fabric.js 保存自定义属性
Python - 类中的对象与属性
本文整理类中对象与属性(变量)相关知识。 类对象与实例对象 建立测试类: class Test: var_of_class = 'Class Var' def __init__(self): self.var_of_instance = 'Instance Var' 类对象 建立类进行编译后则形成了类对象,类对象仅支持两个操作: 实例化:使用instance_name = class_name()的方式实例化,实例化操作创建该类的实例。 属性引用:使用cl
为为为什么
2022/08/04
2.7K0
Swift — 面向对象中类和对象的属性
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/115585.html原文链接:https://javaforall.cn
全栈程序员站长
2022/07/10
2.6K0
Fabric.js 自定义子类,创建属于自己的图形~
虽然 fabric.js 提供了非常简单的方法创建自定义子类,但如果需要创建复杂的图形,还是需要有一定 canvas 基础的。
德育处主任
2022/09/23
1.7K0
Fabric.js 自定义子类,创建属于自己的图形~
关于子类在继承父类属性和方法的基础上如何增加子类的属性和方法
如何用python程序实现子类在继承父类属性和方法的基础上同时增加子类自己的属性和方法?
算法与编程之美
2023/08/22
1850
关于子类在继承父类属性和方法的基础上如何增加子类的属性和方法
iOS开发中访问并修改一个类的私有属性
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010105969/article/details/70037605
用户1451823
2018/09/13
2.7K0
理解Python中的类对象、实例对象、属性、方法
class Animal(object): # 类对象 age = 0 # 公有类属性 __like = None # 私有类属性 def __init__(self): # 魔法方法 self.name = 'haha' # 公有实例属性 self.__sex = 'man' # 私有实例属性 def smile(self): # 公有方法 self指向实例对象 pass def __jump(
汪凡
2018/05/29
3.9K0
SpringBoot返回枚举对象中的所有属性以对象的形式返回(一个@JSONType解决)
最近小编在开发中遇到个问题,就是关于枚举方面的使用。一些固定不变的数据我们可以通过枚举来定义,减少对数据库的查询。是一种常见的开发技巧!
掉发的小王
2022/07/11
3.9K0
子类调用父类的同名方法和属性
在这里,定义Prentice类,继承了Master和School类,添加了和父类同名属性和方法
北山啦
2022/10/31
1.9K0
python中的类,对象,方法,属性初认识
面向对象编程需要使用类,类和实例息息相关,有了类之后我们必须创建一个实例,这样才能调用类的方法。首先看一下类的结构模式:
良月柒
2019/03/20
1.8K0
python中的类,对象,方法,属性初认识
创建子类对象时,父类构造函数中调用被子类重写的方法为什么调用的是子类的方法?
问题:为什么创建A对象的时候父类会调用子类方法? 但是:创建B对象父类会调用父类的方法?
zhangheng
2020/04/28
6.3K0
js给数组中对象添加新属性
let person =[{ id: 1, name: 'vhen' },{ id: 2, name: 'json' }] let newArr = obj.map((item,index) =>{ return Object.assign(item,{index:index}) }) 多添加了一些属性,是为了区别字符串单引号和双引号的, 用了.就不用中括号不用单引号 不用点 就要用中括号和单引号 var a =[{name: 'Tom',age:20},{name: 'Tom2'
用户1349575
2022/01/24
20.6K0
如何遍历JavaScript中对象属性
在2016年6月发布的ECMAScript 2016的同一时期,令JavaScript开发人员开心的是知道另一组很棒的提案已经达到了第4阶段(完成)。
疯狂的技术宅
2019/03/27
3.6K0
如何遍历JavaScript中对象属性
PHP面向对象-对象属性的访问和修改
可以使用对象实例的箭头运算符 -> 来访问对象属性。这个运算符后面跟着属性名。例如,如果有一个名为 $person 的对象实例,它有一个名为 $name 的属性,那么可以这样访问它:
堕落飞鸟
2023/04/27
2.1K0
选择篇(024)-所有对象都有原型吗?
在js中所有通过对象创建的对象,都有一个原型。这些对象都有一个通过原型链接的父级,而这些链接起对象的原型就是原型链。
齐丶先丶森
2022/05/12
1.2K0
点击加载更多

相似问题

如何修改子类中的类的属性?

42

如何强制所有Java类都有一个属性

107

Fabric.js:分组子类对象时缺少的src属性

10

如果所有子对象都有一个属性

40

Python:如何通过子类修改父类的属性?

14
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文