首页 > 解决方案 > 错误:类 Builder 中的构造函数 Builder 不能应用于给定类型;

问题描述

我在应用程序中集成了 FCM 通知。我收到错误:类 Builder 中的构造函数 Builder 不能应用于给定类型。在 NotificationCompat 构造函数中我只传递一个参数。如果我传递两个参数,我得到了上述错误。

我得到了 FCM 令牌和消息正文,但是当我在 build.gradle 中的代码下方注释时,FCM 未显示在通知栏上,然后我在 NotificationCompat 构造函数中传递了两个参数,但我收到错误其他 java 文件,如无法解析 getSupportManger、getActionBar(类文件android.support.v7.app.ActionBarActivity not found)请检查下面的代码

    > buildscript {
    >     repositories {
    >         google()
    >         jcenter()
    >     }
    >     dependencies {  
    >         classpath 'com.google.gms:google-services:4.1.0'
    >         classpath 'com.android.tools.build:gradle:3.3.2'
    >         classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
    >     }} allprojects {
    >     repositories {
    >         google()
    >         jcenter()
    >     }} task clean(type: Delete) {    delete rootProject.buildDir } subprojects {
    >     project.configurations.all {
    >         resolutionStrategy.eachDependency { details ->
    >             if (details.requested.group == 'com.android.support'
    >                     && !details.requested.name.contains('multidex') ) {
    >                 details.useVersion "25.3.1"
    >             }        }
    >     } }
    > 
    > showNotification Method    public void showNotification(String
    > title,String message){
    >     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,"")
    >             .setContentTitle("abc")
    >             .setSmallIcon(R.drawable.abc_logo)
    >             .setAutoCancel(true)
    >             .setContentText(message);
    >     NotificationManagerCompat manager= >NotificationManagerCompat.from(this,"MyNotification");//error here

>manager.notify(999,notificationBuilder.build()); }

当我在 gradle 文件中评论 subProject 部分时,我在 Notification Compact 构造函数中传递了两个参数,但在其他 java 文件中出现错误,例如(找不到 android.support.v7.app.ActionBarActivity 的类文件)。我已经在 Notification Compact 构造函数中传递了一个参数,但是我收到了 fcm 消息,但没有在通知栏上显示通知,所以我该怎么办

标签: androidpush-notificationnotificationsfirebase-cloud-messaging

解决方案


推荐阅读