[Android] AudioService: always stay alive + always block headset button events from the OS
Sébastien Toque
git at videolan.org
Fri Jun 22 15:58:05 CEST 2012
android | branch: master | Sébastien Toque <xilasz at gmail.com> | Fri Jun 22 15:57:38 2012 +0200| [6cc5b33317b1915dd1d5e36c8a0494f8084119ab] | committer: Sébastien Toque
AudioService: always stay alive + always block headset button events from the OS
it prevent accidental calls on double click
> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=6cc5b33317b1915dd1d5e36c8a0494f8084119ab
---
vlc-android/src/org/videolan/vlc/AudioService.java | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 86c3c89..12c7c49 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -108,9 +108,9 @@ public class AudioService extends Service {
}
@Override
- public void onStart(Intent intent, int startId) {
- super.onStart(intent, startId);
+ public int onStartCommand(Intent intent, int flags, int startId) {
updateWidget(this);
+ return super.onStartCommand(intent, flags, startId);
}
@Override
@@ -164,10 +164,14 @@ public class AudioService extends Service {
else if (action.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON)) {
KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
- if (mCurrentMedia == null || event == null ||
- telManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)
+ if (event == null || telManager.getCallState() != TelephonyManager.CALL_STATE_IDLE)
return;
+ if (mCurrentMedia == null) {
+ abortBroadcast();
+ return;
+ }
+
switch (event.getKeyCode())
{
/*
@@ -193,8 +197,6 @@ public class AudioService extends Service {
// double click
} else if (time - mHeadsetUpTime <= 500) {
next();
- // block the double click event to prevent android from dialing last number
- abortBroadcast();
}
// one click
else {
@@ -223,6 +225,7 @@ public class AudioService extends Service {
previous();
break;
}
+ abortBroadcast();
}
/*
More information about the Android
mailing list