(#) Notification Id is 0 !!! ERROR: Notification Id is 0 This is an error. Id : `NotificationId0` Summary : Notification Id is 0 Severity : Error Category : Correctness Platform : Android Vendor : Android Open Source Project Feedback : https://issuetracker.google.com/issues/new?component=192708 Since : 7.3.0 (September 2022) Affects : Kotlin and Java files Editing : This check runs on the fly in the IDE editor Implementation : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/InvalidNotificationIdDetector.kt) Tests : [Source Code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InvalidNotificationIdDetectorTest.kt) The notification id **cannot** be 0; using 0 here can make the service not run in the foreground. (##) Example Here is an example of lint warnings produced by this check: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~text src/test/pkg/ServiceTest.kt:13:Error: The notification id cannot be 0 [NotificationId0] service.startForeground(0, notification) // ERROR 1: cannot be zero - src/test/pkg/ServiceTest.kt:14:Error: The notification id cannot be 0 [NotificationId0] service.startForeground(MY_ID, notification, 1) // ERROR 2: cannot be zero ----- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here is the source file referenced above: `src/test/pkg/ServiceTest.kt`: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~kotlin linenumbers package test.pkg import android.app.Notification import android.app.Service private const val MY_ID = 0 class ServiceTest { fun test(service: Service, notification: Notification, unknownId: Int) { service.startForeground(unknownId, notification) // OK: don't know service.startForeground(-1, notification) // OK: valid id service.startForeground(1, notification, 0) // OK: valid id service.startForeground(0, notification) // ERROR 1: cannot be zero service.startForeground(MY_ID, notification, 1) // ERROR 2: cannot be zero } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can also visit the [source code](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/InvalidNotificationIdDetectorTest.kt) for the unit tests for this check to see additional scenarios. (##) Suppressing You can suppress false positives using one of the following mechanisms: * Using a suppression annotation like this on the enclosing element: ```kt // Kotlin @Suppress("NotificationId0") fun method() { startForeground(...) } ``` or ```java // Java @SuppressWarnings("NotificationId0") void method() { startForeground(...); } ``` * Using a suppression comment like this on the line above: ```kt //noinspection NotificationId0 problematicStatement() ``` * Using a special `lint.xml` file in the source tree which turns off the check in that folder and any sub folder. A simple file might look like this: ```xml <?xml version="1.0" encoding="UTF-8"?> <lint> <issue id="NotificationId0" severity="ignore" /> </lint> ``` Instead of `ignore` you can also change the severity here, for example from `error` to `warning`. You can find additional documentation on how to filter issues by path, regular expression and so on [here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html). * In Gradle projects, using the DSL syntax to configure lint. For example, you can use something like ```gradle lintOptions { disable 'NotificationId0' } ``` In Android projects this should be nested inside an `android { }` block. * For manual invocations of `lint`, using the `--ignore` flag: ``` $ lint --ignore NotificationId0 ...` ``` * Last, but not least, using baselines, as discussed [here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).