gpt4 book ai didi

android - NotificationCompat.Builder 不接受第二个参数

转载 作者:行者123 更新时间:2023-12-03 03:06:07 28 4
gpt4 key购买 nike

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

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

构建.gradle:项目
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
}

构建.gradle:应用程序
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; .这是通知 channel 的官方指南,它是 Android O 的新功能:https://developer.android.com/training/notify-user/channels .

关于android - NotificationCompat.Builder 不接受第二个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50765964/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com