From 09b474a51936c9c83df32dfcaf816e37a72552ce Mon Sep 17 00:00:00 2001 From: ibaker Date: Wed, 3 May 2023 16:29:35 +0000 Subject: [PATCH] Use a for-each loop instead of `forEach` in `PlaybackService.kt` The current code flags a lint error: ``` Error: Call requires API level 24 (current min is 16): java.lang.Iterable#forEach [NewApi] ``` I think this is a bit confusing because this is calling the Java [`Iterable.forEach`](https://developer.android.com/reference/java/lang/Iterable#forEach(java.util.function.Consumer%3C?%20super%20T%3E)) method which was added in Java 8 (and therefore is only available on API 24 and up), but there is **also** a Kotlin [`List.forEach`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/for-each.html) method which is available in all versions of Kotlin (and therefore all Android versions). Since this is a Kotlin file, at first glance you would assume this is the Kotlin method - but it's not. This also doesn't seem to be flagged by Android Studio, but is caught by Gradle lint on the command line. #minor-release PiperOrigin-RevId: 529112610 --- .../main/java/androidx/media3/demo/session/PlaybackService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/session/src/main/java/androidx/media3/demo/session/PlaybackService.kt b/demos/session/src/main/java/androidx/media3/demo/session/PlaybackService.kt index d930c05182..738cf0e0d5 100644 --- a/demos/session/src/main/java/androidx/media3/demo/session/PlaybackService.kt +++ b/demos/session/src/main/java/androidx/media3/demo/session/PlaybackService.kt @@ -97,7 +97,7 @@ class PlaybackService : MediaLibraryService() { ): MediaSession.ConnectionResult { val connectionResult = super.onConnect(session, controller) val availableSessionCommands = connectionResult.availableSessionCommands.buildUpon() - customCommands.forEach { commandButton -> + for (commandButton in customCommands) { // Add custom command to available session commands. commandButton.sessionCommand?.let { availableSessionCommands.add(it) } }