Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[GUIDE] Customizing Sony W. Button behaviour

OP mazze1200

12th January 2014, 08:18 PM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Jun 2009
I recently got an SONY NWZ-F806 Walkman with Android. I bought it to listen to Spotify and everything works fine but the fact that you cannot control Spotify with the the dedicated W. button on the side of the device.

So I googled and found a solution where you had to redirect the W. button to the search button which was not satisfying to me. So I decided to investigate deeper into this and with a little help of adb and dumpsys I found the Intent that was fired when the W. button is pressed "com.sony.walkman.intent.action.WALKMAN_BUTTON ". Than I found the service which was responsible for the default behavior "W.control".

So to redirect the W. button to Spotify I had to do the following things:

1) Disable the default W. behavior
To do this you simply have to deactivate the W.control service
Systemsettings > Apps > All > W.control > Disable

2) To listen to the W. button a BroadcastReceiver has to be implemented which receives to the Intent "com.sony.walkman.intent.action.WALKMAN_BUTTON " and sends a Intent to Spotify

AndroidManifest.xml
Code:
    <application>
        <receiver android:name=".WDotReceiver" >
            <intent-filter>
                <action android:name="com.sony.walkman.intent.action.WALKMAN_BUTTON" />
            </intent-filter>
        </receiver>
    </application>
WDotReceiver.java
Code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;

public class WDotReceiver extends BroadcastReceiver {
	private static final String KEY_EVENT_KEY = "android.intent.extra.KEY_EVENT";
	private static final String SPOTIFY_PLAY_KEY = "com.spotify.mobile.android.ui.widget.PLAY";
	private static final String SPOTIFY_NEXT_KEY = "com.spotify.mobile.android.ui.widget.NEXT";

	@Override
	public void onReceive(Context arg0, Intent arg1) {
		Bundle extrasBundle =  arg1.getExtras();
		if(extrasBundle != null)
		{
			if(extrasBundle.containsKey(KEY_EVENT_KEY))
			{
				KeyEvent keyEvent =  extrasBundle.getParcelable(KEY_EVENT_KEY);
	
				if(keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getRepeatCount() == 0)
				{
					arg0.sendBroadcast(new Intent(SPOTIFY_PLAY_KEY));
				}
				else if(keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getRepeatCount() == 1)
				{
					arg0.sendBroadcast(new Intent(SPOTIFY_NEXT_KEY));
				}
			}
		}
	}
}
If you press the W. button for a short time a Play/Pause Intent is send and if you press the button longer Spotify will skip to the next track.

To me this increases the usability of the device tremendously.

Kind regards
Mathias
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes