[Android] Prevent crash on Oreo when app is in background

Geoffrey Métais git at videolan.org
Fri Mar 30 16:25:42 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Mar 30 09:45:03 2018 +0200| [73845dd1d2e0aca436c9bfe6faf6e4cf240eed09] | committer: Geoffrey Métais

Prevent crash on Oreo when app is in background

> https://code.videolan.org/videolan/vlc-android/commit/73845dd1d2e0aca436c9bfe6faf6e4cf240eed09
---

 .../src/org/videolan/vlc/RemoteControlClientReceiver.java        | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java b/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
index 65302b48e..a66d8adf8 100644
--- a/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
+++ b/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
@@ -44,13 +44,20 @@ public class RemoteControlClientReceiver extends MediaButtonReceiver {
     @Override
     public void onReceive(Context context, Intent intent) {
         final String action = intent.getAction();
+        if (action == null) return;
 
         final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
         if (event != null && action.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON)) {
 
             if (event.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK &&
                     event.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
-                super.onReceive(context, intent);
+                if (!AndroidUtil.isOOrLater || VLCApplication.isForeground()) super.onReceive(context, intent);
+                else if (event.getAction() == KeyEvent.ACTION_DOWN &&
+                         event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY) {
+                    intent = new Intent(context, PlaybackService.class);
+                    intent.setAction(Constants.ACTION_REMOTE_PLAYPAUSE);
+                    Util.startService(context, intent);
+                }
                 return;
             }
 



More information about the Android mailing list