[Android] fix callback leak + pause playback for both incoming and outgoing calls

Sébastien Toque git at videolan.org
Thu Mar 1 22:19:49 CET 2012


android | branch: master | Sébastien Toque <xilasz at gmail.com> | Thu Mar  1 22:09:49 2012 +0100| [1bf432ee5fa91138aaf25f049b02c59149a357f0] | committer: Sébastien Toque

fix callback leak + pause playback for both incoming and outgoing calls

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=1bf432ee5fa91138aaf25f049b02c59149a357f0
---

 .../src/org/videolan/vlc/PhoneStateReceiver.java   |   24 +++++++------------
 1 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PhoneStateReceiver.java b/vlc-android/src/org/videolan/vlc/PhoneStateReceiver.java
index a2c49f9..723ab7d 100644
--- a/vlc-android/src/org/videolan/vlc/PhoneStateReceiver.java
+++ b/vlc-android/src/org/videolan/vlc/PhoneStateReceiver.java
@@ -23,27 +23,21 @@ package org.videolan.vlc;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
-import android.telephony.PhoneStateListener;
 import android.telephony.TelephonyManager;
 
 public class PhoneStateReceiver extends BroadcastReceiver {
 
-    private PhoneStateListener mListener = new PhoneStateListener() {
-        @Override
-        public void onCallStateChanged(int state, String incomingNumber) {
-            if (state == TelephonyManager.CALL_STATE_RINGING) {
-                LibVLC libVLC = LibVLC.getExistingInstance();
-                if (libVLC != null && libVLC.isPlaying())
-                    libVLC.pause();
-            }
-        }
-    };
-
     @Override
     public void onReceive(Context context, Intent intent) {
-        TelephonyManager tm = (TelephonyManager)
-                context.getSystemService(Context.TELEPHONY_SERVICE);
-        tm.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE);
+        String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
+
+        if (state.equals(TelephonyManager.EXTRA_STATE_RINGING) ||
+                state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
+
+            LibVLC libVLC = LibVLC.getExistingInstance();
+            if (libVLC != null && libVLC.isPlaying())
+                libVLC.pause();
+        }
     }
 
 }



More information about the Android mailing list