Skip to content

Commit 2895770

Browse files
committed
Merge branch 'fix_stop_foreground' into minor
2 parents 60c6dfd + 73faee8 commit 2895770

File tree

16 files changed

+82
-101
lines changed

16 files changed

+82
-101
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ gradlew
4747
gradlew.bat
4848
local.properties
4949
**/GeneratedPluginRegistrant.java
50+
**/.cxx/
5051

5152
# Android Studio will place build artifacts here
5253
**/android/app/debug

audio_service/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## 0.18.18
22

33
* Fix setPlaybackState entitlement issue on iOS.
4+
* Fix Android stopForeground deprecation warning.
5+
* Bump compile/target SDK to 35 on Android.
6+
* Bump minSdk to 19 on Android.
7+
* bump AGP to 8.5.2.
48

59
## 0.18.17
610

audio_service/android/build.gradle

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
group 'com.ryanheise.audioservice'
2-
version '1.0-SNAPSHOT'
1+
group = "com.ryanheise.audioservice"
2+
version "1.0-SNAPSHOT"
33
def args = ["-Xlint:deprecation","-Xlint:unchecked"]
44

55
buildscript {
6+
ext {
7+
agp_version = '8.5.2'
8+
}
69
repositories {
710
google()
811
mavenCentral()
912
}
1013

1114
dependencies {
12-
classpath 'com.android.tools.build:gradle:7.3.0'
15+
classpath "com.android.tools.build:gradle:$agp_version"
1316
}
1417
}
1518

@@ -24,29 +27,25 @@ project.getTasks().withType(JavaCompile) {
2427
options.compilerArgs.addAll(args)
2528
}
2629

27-
apply plugin: 'com.android.library'
30+
apply plugin: "com.android.library"
2831

2932
android {
30-
// Conditional for compatibility with AGP <4.2.
31-
if (project.android.hasProperty("namespace")) {
32-
namespace 'com.ryanheise.audioservice'
33-
}
34-
compileSdkVersion 33
33+
namespace "com.ryanheise.audioservice"
34+
compileSdk = 35
3535

3636
compileOptions {
37-
sourceCompatibility JavaVersion.VERSION_1_8
38-
targetCompatibility JavaVersion.VERSION_1_8
37+
sourceCompatibility = JavaVersion.VERSION_11
38+
targetCompatibility = JavaVersion.VERSION_11
3939
}
4040
defaultConfig {
41-
minSdkVersion 16
42-
targetSdkVersion 33
43-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
41+
minSdk = 19
4442
}
4543
lintOptions {
4644
disable 'InvalidPackage'
4745
}
4846
}
4947

5048
dependencies {
51-
implementation 'androidx.media:media:1.6.0'
49+
implementation 'androidx.media:media:1.7.0'
50+
implementation 'androidx.core:core:1.13.1'
5251
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
34
zipStoreBase=GRADLE_USER_HOME
45
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.ryanheise.audioservice">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
</manifest>

audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import android.view.KeyEvent;
3030

3131
import androidx.annotation.RequiresApi;
32+
import androidx.core.app.ServiceCompat;
3233
import androidx.core.content.ContextCompat;
3334
import androidx.core.app.NotificationCompat;
3435
import androidx.media.MediaBrowserServiceCompat;
@@ -371,7 +372,7 @@ public void onDestroy() {
371372
artBitmapCache.evictAll();
372373
compactActionIndices = null;
373374
releaseMediaSession();
374-
legacyStopForeground(!config.androidResumeOnClick);
375+
ServiceCompat.stopForeground(this, config.androidResumeOnClick ? STOP_FOREGROUND_DETACH : STOP_FOREGROUND_REMOVE);
375376
// This still does not solve the Android 11 problem.
376377
// if (notificationCreated) {
377378
// NotificationManager notificationManager = getNotificationManager();
@@ -382,18 +383,6 @@ public void onDestroy() {
382383
notificationCreated = false;
383384
}
384385

385-
@SuppressWarnings("deprecation")
386-
private void legacyStopForeground(boolean removeNotification) {
387-
if (Build.VERSION.SDK_INT >= 24) {
388-
// TODO: Consider application of STOP_FOREGROUND_DETACH
389-
stopForeground(removeNotification ? STOP_FOREGROUND_REMOVE : 0);
390-
} else {
391-
// TODO: This API is deprecated and we'll need to eventually
392-
// delete this line.
393-
stopForeground(removeNotification);
394-
}
395-
}
396-
397386
public AudioServiceConfig getConfig() {
398387
return config;
399388
}
@@ -730,7 +719,7 @@ private void exitPlayingState() {
730719
}
731720

732721
private void exitForegroundState() {
733-
legacyStopForeground(false);
722+
ServiceCompat.stopForeground(this, STOP_FOREGROUND_DETACH);
734723
releaseWakeLock();
735724
}
736725

audio_service/example/android/app/build.gradle

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,29 @@
1-
def localProperties = new Properties()
2-
def localPropertiesFile = rootProject.file('local.properties')
3-
if (localPropertiesFile.exists()) {
4-
localPropertiesFile.withReader('UTF-8') { reader ->
5-
localProperties.load(reader)
6-
}
7-
}
8-
9-
def flutterRoot = localProperties.getProperty('flutter.sdk')
10-
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12-
}
13-
14-
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15-
if (flutterVersionCode == null) {
16-
flutterVersionCode = '1'
17-
}
18-
19-
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20-
if (flutterVersionName == null) {
21-
flutterVersionName = '1.0'
1+
plugins {
2+
id "com.android.application"
3+
id "kotlin-android"
4+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5+
id "dev.flutter.flutter-gradle-plugin"
226
}
237

24-
apply plugin: 'com.android.application'
25-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
26-
278
android {
28-
namespace 'com.ryanheise.audioserviceexample'
29-
compileSdkVersion 34
9+
namespace = "com.ryanheise.audioserviceexample"
10+
compileSdk = flutter.compileSdkVersion
11+
12+
compileOptions {
13+
sourceCompatibility = JavaVersion.VERSION_11
14+
targetCompatibility = JavaVersion.VERSION_11
15+
}
3016

31-
lintOptions {
32-
disable 'InvalidPackage'
17+
kotlinOptions {
18+
jvmTarget = JavaVersion.VERSION_11
3319
}
3420

3521
defaultConfig {
3622
applicationId "com.ryanheise.audioserviceexample"
37-
minSdkVersion 21
38-
targetSdkVersion 34
39-
versionCode flutterVersionCode.toInteger()
40-
versionName flutterVersionName
41-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
23+
minSdk = flutter.minSdkVersion
24+
targetSdk = flutter.targetSdkVersion
25+
versionCode = flutter.versionCode
26+
versionName = flutter.versionName
4227
}
4328

4429
buildTypes {
@@ -49,6 +34,10 @@ android {
4934
shrinkResources true
5035
}
5136
}
37+
38+
lint {
39+
disable = ["InvalidPackage"]
40+
}
5241
}
5342

5443
flutter {

audio_service/example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.ryanheise.audioserviceexample">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
<!-- Flutter needs it to communicate with the running application
43
to allow setting breakpoints, to provide hot reload, etc.
54
-->

audio_service/example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
xmlns:tools="http://schemas.android.com/tools"
3-
package="com.ryanheise.audioserviceexample">
2+
xmlns:tools="http://schemas.android.com/tools">
43

54
<uses-permission android:name="android.permission.INTERNET"/>
65
<uses-permission android:name="android.permission.WAKE_LOCK"/>

audio_service/example/android/build.gradle

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
buildscript {
2-
repositories {
3-
google()
4-
mavenCentral()
5-
}
6-
7-
dependencies {
8-
classpath 'com.android.tools.build:gradle:7.3.0'
9-
}
10-
}
11-
121
allprojects {
132
repositories {
143
google()
154
mavenCentral()
165
}
176
}
187

19-
rootProject.buildDir = '../build'
8+
rootProject.buildDir = "../build"
209
subprojects {
2110
project.buildDir = "${rootProject.buildDir}/${project.name}"
2211
}
2312
subprojects {
24-
project.evaluationDependsOn(':app')
13+
project.evaluationDependsOn(":app")
2514
}
2615

2716
tasks.register("clean", Delete) {

0 commit comments

Comments
 (0)