Skip to content

Commit df4e87a

Browse files
committed
RemoveController: fix foreground service not allowed
1 parent 21eb2a9 commit df4e87a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.liskovsoft.smartyoutubetv2.common.misc;
22

3+
import android.annotation.SuppressLint;
34
import android.content.BroadcastReceiver;
45
import android.content.Context;
56
import android.content.Intent;
@@ -10,18 +11,19 @@
1011
public class RemoteControlReceiver extends BroadcastReceiver {
1112
private static final String TAG = RemoteControlReceiver.class.getSimpleName();
1213

14+
@SuppressLint("UnsafeProtectedBroadcastReceiver")
1315
@Override
1416
public void onReceive(Context context, Intent intent) {
1517
Log.d(TAG, "Initializing remote control listener...");
1618

1719
// Fix unload from the memory on some devices?
1820
// NOTE: Starting from Android 12 (api 31) foreground service with type 'connectedDevice' not supported
1921
// Use 'mediaPlayback' type instead
20-
Utils.updateRemoteControlService(context);
21-
22-
//Utils.startRemoteControlWorkRequest(context);
23-
24-
// Couldn't success inside periodic work request
25-
//PlaybackPresenter.instance(context); // init RemoteControlListener
22+
try {
23+
Utils.updateRemoteControlService(context);
24+
} catch (Exception e) {
25+
// ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false (Android 12)
26+
e.printStackTrace();
27+
}
2628
}
2729
}

0 commit comments

Comments
 (0)