NotificationCompat.Builder 不接受第二个参数 [英] NotificationCompat.Builder doesn't accept 2nd argument

查看:29
本文介绍了NotificationCompat.Builder 不接受第二个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

For some reason my NotificationCompat.Builder will not accept 2nd argument and I have no idea how to fix it. I saw some other answers but mostly the problem was in the gradle version, but mine is up-to-date as shown below:

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 文件

and these are my gradle files

build.gradle:project

build.gradle:project

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

build.gradle:app

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'
    }

有什么想法吗?

推荐答案

请确保您包含了正确版本的 NotificationCompat 库:import android.support.v4.app.NotificationCompat;.这是通知渠道的官方指南,这是 Android O 的新功能:https://developer.android.com/training/notify-user/channels.

Please make sure that you are including the correct version of the NotificationCompat library: import android.support.v4.app.NotificationCompat;. Here is the official guide on Notification Channels, which are a new feature as of Android O: https://developer.android.com/training/notify-user/channels.

这篇关于NotificationCompat.Builder 不接受第二个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆