[Android] Add an option to "steal" headset remote control from other apps
Sébastien Toque
git at videolan.org
Tue Nov 6 22:32:56 CET 2012
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Tue Nov 6 21:56:28 2012 +0100| [7d43022b4121267dcee02ff3a81f3c19f3939238] | committer: Sébastien Toque
Add an option to "steal" headset remote control from other apps
On HTC phones, a double click on media button triggers a call to the last number.
This is annoying, since we use double click on media button to switch to next song.
Because RemoteControlClient event are not ordered, they can't be aborted.
When the event reachs the RemoteControlClientReceiver, it's already too late,
the OS (or whatever triggers a call) has also received the event and we can't do anything.
A workaround is to use a receiver on ACTION_MEDIA_BUTTON with high priority
(Integer.MAX_VALUE) instead of a regular RemoteControlClientReceiver.
Since ACTION_MEDIA_BUTTON events are sent before any RemoteControlClient events
and are ordered, they can be aborted.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=7d43022b4121267dcee02ff3a81f3c19f3939238
---
vlc-android/res/values-fr/strings.xml | 2 ++
vlc-android/res/values/strings.xml | 2 ++
vlc-android/res/xml/preferences.xml | 7 ++++++-
vlc-android/src/org/videolan/vlc/AudioService.java | 9 ++++++++-
.../src/org/videolan/vlc/RemoteControlClientReceiver.java | 2 ++
5 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/vlc-android/res/values-fr/strings.xml b/vlc-android/res/values-fr/strings.xml
index fd5dee2..5792d0a 100644
--- a/vlc-android/res/values-fr/strings.xml
+++ b/vlc-android/res/values-fr/strings.xml
@@ -120,6 +120,8 @@
<string name="media_db_cleared">Base de données multimedia vidée!</string>
<string name="detect_headset">Détecter le casque</string>
<string name="detect_headset_detail">Pause lors du débranchement du casque, Reprise lors du branchement du casque</string>
+ <string name="steal_remote_control">Voler le contrôle de la télécommande aux autres applis</string>
+ <string name="steal_remote_control_detail">Evite les conflits en volant le contrôle de la télécommande aux autres applis. Cela empêche le double clic de rappeler le dernier numéro sur les téléphones HTC</string>
<string name="enable_wheel_bar">Activer la wheel bar</string>
<string name="enable_gesture_brightness">Activer le geste de luminosité</string>
<string name="enable_verbose_mode">Verbosité</string>
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 18ab425..ce8d9ec 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -163,6 +163,8 @@
<string name="set_locale_popup">Quit and reset VLC for changes to take effect.</string>
<string name="detect_headset">Detect headset</string>
<string name="detect_headset_detail">Pause on headset removed; resume on headset inserted</string>
+ <string name="steal_remote_control">Steal headset remote control from other apps</string>
+ <string name="steal_remote_control_detail">Avoid conflicts by stealing the remote control from other apps. This prevent dialing on double click on HTC phones</string>
<string name="enable_wheel_bar">Enable wheel bar</string>
<string name="enable_gesture_brightness">Enable brightness gesture</string>
<string name="enable_verbose_mode">Verbose</string>
diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml
index cf74005..7ebd853 100644
--- a/vlc-android/res/xml/preferences.xml
+++ b/vlc-android/res/xml/preferences.xml
@@ -23,6 +23,12 @@
android:defaultValue="true">
</CheckBoxPreference>
<CheckBoxPreference
+ android:key="steal_remote_control"
+ android:title="@string/steal_remote_control"
+ android:summary="@string/steal_remote_control_detail"
+ android:defaultValue="false">
+ </CheckBoxPreference>
+ <CheckBoxPreference
android:key="enable_wheel_bar"
android:title="@string/enable_wheel_bar"
android:defaultValue="false">
@@ -31,7 +37,6 @@
android:defaultValue="true"
android:key="enable_gesture_brightness"
android:title="@string/enable_gesture_brightness" >
-
</CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/privacy_prefs_category">
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 02a06ab..ba03cbd 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -40,6 +40,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
@@ -51,6 +52,7 @@ import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
+import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -137,9 +139,14 @@ public class AudioService extends Service {
filter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
registerReceiver(serviceReceiver, filter);
- if(!Util.isFroyoOrLater()) {
+ final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
+ boolean stealRemoteControl = pref.getBoolean("steal_remote_control", false);
+
+ if(!Util.isFroyoOrLater() || stealRemoteControl) {
/* Backward compatibility for API 7 */
filter = new IntentFilter();
+ if (stealRemoteControl)
+ filter.setPriority(Integer.MAX_VALUE);
filter.addAction(Intent.ACTION_MEDIA_BUTTON);
registerReceiver(new RemoteControlClientReceiver(), filter);
}
diff --git a/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java b/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
index b87fbed..67b8de6 100644
--- a/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
+++ b/vlc-android/src/org/videolan/vlc/RemoteControlClientReceiver.java
@@ -114,6 +114,8 @@ public class RemoteControlClientReceiver extends BroadcastReceiver {
break;
}
+ if (isOrderedBroadcast())
+ abortBroadcast();
if(i != null)
context.sendBroadcast(i);
}
More information about the Android
mailing list