Skip to content

Commit 18d74f9

Browse files
committed
remote service: another Android 14 fix; upd MediaServiceCore
1 parent 321a1f2 commit 18d74f9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

common/src/main/java/com/liskovsoft/smartyoutubetv2/common/misc/RemoteControlService.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
import android.app.Notification;
44
import android.app.Service;
55
import android.content.Intent;
6+
import android.content.pm.ServiceInfo;
67
import android.os.Build.VERSION;
78
import android.os.IBinder;
8-
import android.support.v4.media.session.MediaSessionCompat;
99

1010
import androidx.annotation.Nullable;
1111

12-
import com.liskovsoft.sharedutils.helpers.AppInfoHelpers;
1312
import com.liskovsoft.sharedutils.helpers.Helpers;
1413
import com.liskovsoft.sharedutils.mylogger.Log;
1514
import com.liskovsoft.smartyoutubetv2.common.R;
@@ -37,13 +36,18 @@ public void onCreate() {
3736
// NOTE: it's impossible to hide notification on Android 9 and above
3837
// https://stackoverflow.com/questions/10962418/how-to-startforeground-without-showing-notification
3938
try {
40-
if (AppInfoHelpers.getRealSdkVersion(this) >= 34) { // Fix ForegroundServiceStartNotAllowedException
41-
// Tie service to active media session
42-
MediaSessionCompat mediaSession = new MediaSessionCompat(this, TAG);
43-
mediaSession.setActive(true);
44-
}
39+
//if (AppInfoHelpers.getRealSdkVersion(this) >= 34) { // Fix ForegroundServiceStartNotAllowedException
40+
// // Tie service to active media session
41+
// MediaSessionCompat mediaSession = new MediaSessionCompat(this, TAG);
42+
// mediaSession.setActive(true);
43+
//}
4544

46-
startForeground(NOTIFICATION_ID, createNotification());
45+
if (VERSION.SDK_INT >= 34) {
46+
// Fix ForegroundServiceStartNotAllowedException on Android 14?
47+
startForeground(NOTIFICATION_ID, createNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
48+
} else {
49+
startForeground(NOTIFICATION_ID, createNotification());
50+
}
4751
} catch (NullPointerException e) {
4852
// NullPointerException: Attempt to read from field 'int com.android.server.am.UidRecord.curProcState' on a null object reference
4953
e.printStackTrace();

0 commit comments

Comments
 (0)