首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >NotificationCompat.Builder不接受第二个参数

NotificationCompat.Builder不接受第二个参数
EN

Stack Overflow用户
提问于 2018-06-09 01:44:45
回答 1查看 4K关注 0票数 2

由于某些原因,我的NotificationCompat.Builder不接受第二个参数,我不知道如何修复它。我看到了一些其他的答案,但大多数问题都在gradle版本中,但我的答案是最新的,如下所示:

代码语言:javascript
复制
if (Build.VERSION.SDK_INT >= 26) {
        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent mPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        Notification mNotification = new NotificationCompat.Builder(this, CHANNEL_ID)
                .setContentTitle("Content Title")
                .setContentText("Content Text")
                .setSmallIcon(R.drawable.ic_check)
                .setContentIntent(mPendingIntent)
                .build();

            startForeground(1, mNotification);
            mNotification.notify();
        }

这些是我的gradle文件

build.gradle:project

代码语言:javascript
复制
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle:app

代码语言:javascript
复制
apply plugin: 'com.android.application'

    android {
        compileSdkVersion 26
        defaultConfig {
            applicationId "rs.dreamlight.parkomat"
            minSdkVersion 15
            targetSdkVersion 26
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }


    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support:support-v4:26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        implementation 'com.android.support:support-vector-drawable:26.1.0'
        implementation 'com.google.code.gson:gson:2.8.4'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
        implementation 'com.android.support:design:26.1.0'
        implementation 'com.android.support:cardview-v7:26.1.0'
        implementation 'com.github.clans:fab:1.6.4'
    }

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-09 04:29:57

请确保包含正确版本的NotificationCompat库:import android.support.v4.app.NotificationCompat;。这是关于通知频道的官方指南,这是安卓O:https://developer.android.com/training/notify-user/channels的一个新功能。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50765964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档