Get Android Notifications on XBMC

I love XBMC.  When the XBOX360  came out I modded my Xbox to become a media center and loved it.  I’ve since upgraded to a PC running XBMC.  In this article we’re gonna look at how to get notifications from an Android phone to XBMC.

This can be a useful tool to have.  For example, I have set it up so that when my cell phone rings XBMC pauses whatever I’m watching and shows a popup message with the Caller ID.

So, let’s get started.  I’ll be using a Windows PC for this tutorial.  This is equally possible to do on Linux, and maybe I’ll write another article describing how to achieve this using Bash Scripting instead of CMD Batch Scripts.  But, for now, let’s focus on Windows.

First you’ll need the following software:

Remote Notifier for Android (Android Market)

Remote Notifier Desktop for Windows (Download)

UnxUtils (Download)

First things first.  Let’s setup XBMC to receive the notifications.  The first thing we need to do is setup XBMC to have a static IP.  If we don’t set this up we won’t know where to send the notifications.  If you’re using the Windows installation of XBMC goto your adapter setting and set your IP there.  if you are using the live or linux installations of XBMC heres what you do.  Open a terminal window and type the following.

$ sudo nano /etc/network/interfaces

When nano opens, you should see something like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface

auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

At the end, remove dhcp and chage it to static and add the following

address 192.168.1.200
netmask 255.255.255.0
network 192.168.1..0
broadcast 192.168.1.255
gateway 192.168.1.1

This assumes your ip scheme is 192.168.1.whatever if it’s not, change it to what you are using.

Press Ctrl + O to save and Ctrl + X to exit. To setup your DNS settings you can use nano to edit /etc/resolv.conf

After you’re done and back in the terminal type the following

$ sudo /etc/init.d/networking restart

Or you can just restart the machine by typing the following

$ sudo shutdown -r now

Back in XBMC goto Settings > Network >Services.  Here you need to enable the “Allow control of XBMC via HTTP” setting.  Set the port to 8080.  Set the Username and Password.  For this tutorial we will assume you set the username as xbmc and the password as xbmc.

Now that that’s done, install the Remote Notifier app on your phone.  Once installed, open the app and select “Notification service.” Select Start service at boot, and deselect “Show notification icon.” Go Back and choose “Notification methods.”  Here select “IP/Wifi.” Now select “IP/Wifi options.  Here you should select “Auto-enable wifi.”  This will counteract the tendency for Android to turn off wifi when the screen shuts off, thus making it so messages aren’t send to XBMC if the phone’s screen is off.  An alternative is to have wifi never shut off, but this can drain battery life while around wifi access points that your phone logs into.  Go back to Remote Notifier’s main menu and choose “Events to notify.”  Here choose the things you want to be notified of on XBMC.  I have selected Phone ring, SMS, MMS, and Voicemail.  You can also setup security to encrypt your notifications, but for simplicity, we will not be doing that in this tutorial.  So, let’s move on to the PC.

Ok, first things first. on the C drive create a directory to work from, I called mine XBMC.  Download UnxUtils and open the zip file.  In the usrlocalwbin directory find wget.exe, cat.exe and grep.exe and place them in C:XBMC.  Now, we’re going to create two batch files.  One for notifying when the phone is ringing, which will check if something is playing and then pause it, and one that just sends the notification.

notifyphone.bat
@echo off

::Make sure we are working in the directory with the *nix commands (change to XBMC the directory you placed unxutils in)
cd XBMC


::Make variable local in scope and enable delayed expansion
setlocal EnableDelayedExpansion

::Set Variables
set ip=192.168.1.200
set port=8080
set user=xbmc
set pass=xbmc

::Set title to the first command argument without quotes
set title=%~1

::Set message to the second command argument without quotes
set message=%~2

::Check if connection is alive
::Check windows version to decide on ping response
For /f "tokens=2 delims=[]" %%A in ('ver') Do set _ver=%%A
For /f "tokens=2 delims=. " %%A in ('echo !_ver!') Do set _ver=%%A

::If not XP jump over the XP specific ping response and look for Vista/Win7 response
if !_ver! GTR 5 goto notXP
FOR /F "tokens=4 delims= " %%A in ('ping -n 1 !ip! ^| grep "Request timed out"') do set _retval=%%A
goto continue

:notXP
FOR /F “tokens=4 delims= ” %%A in (‘ping -n 1 !ip! ^| grep “Destination host unreachable”‘) do set _retval=%%A

:continue
::If not alive, jump to the end of the script
if defined _retval goto end

::Otherwise continue by checking if a video or music is playing
wget -q -O temp.txt http://!user!:!pass!@!ip!:!port!/xbmcCmds/xbmcHttp?command=GetCurrentlyPlaying()
for /f "tokens=2 delims=:" %%a in ('cat temp.txt ^| grep "PlayStatus"') do set _myval=%%a

::If something is playing, pause it
if defined _myval (
if "!_myval!"=="Playing" (
wget -O temp.txt -q "http://!user!:!pass!@!ip!:!port!/xbmcCmds/xbmcHttp?command=Pause()"
)
)

::Send the notification
wget -O temp.txt -q "http://!user!:!pass!@!ip!:!port!/xbmcCmds/xbmcHttp?command=ExecBuiltIn(Notification(!title!,!message!,8000))"

del temp.txt

:end
endlocal

notify.bat
@echo off

::Make sure we are working in the directory with the *nix commands (change to XBMC the directory you placed unxutils in)
cd XBMC

::Make variable local in scope and enable delayed expansion
setlocal EnableDelayedExpansion

::Set Variables
set ip=192.168.1.200
set port=8080
set user=xbmc
set pass=xbmc

::Set title to the first command argument without quotes
set title=%~1

::Set message to the second command argument without quotes
set message=%~2

::Check if connection is alive
::Check windows version to decide on ping response
For /f "tokens=2 delims=[]" %%A in ('ver') Do set _ver=%%A
For /f "tokens=2 delims=. " %%A in ('echo !_ver!') Do set _ver=%%A


::If not XP jump over the XP specific ping response and look for Vista/Win7 response
if !_ver! GTR 5 goto notXP
FOR /F "tokens=4 delims= " %%A in ('ping -n 1 !ip! ^| grep "Request timed out"') do set _retval=%%A

goto continue

:notXP
FOR /F "tokens=4 delims= " %%A in ('ping -n 1 !ip! ^| grep "Destination host unreachable"') do set _retval=%%A

:continue
::If not alive, jump to the end of the script
if defined _retval goto end

::Send the notification
wget -O temp.txt -q "http://!user!:!pass!@!ip!:!port!/xbmcCmds xbmcHttp?command=ExecBuiltIn(Notification(!title!,!message!,8000))"


del temp.txt

:end
endlocal

Once these are saved into C:XBMC we’re ready to move on to the next step.  If you haven’t already, install Remote Notifier Desktop app.  Open it.  It will now reside in your SysTray (by the clock.)  Right click the icon and choose Preferences.  Place a check mark in “Start at login,” place a check mark in “Wifi,” and place a check mark in “System default.”  Now, under Notification Actions you will see a bunch of tabs.  One for each event.  In the events you selected on your phone, place a check mark in “Enabled” and “Execute Commands.”  In the textbox under “Execute Commands” enter the following

For Ring event
c:XBMCnotifyphone.bat {title} "{description}"

For all other events
c:nixnotify.bat {title} "{description}"

Click Save and you’re done!

Now you will get messages from your Android phone to your XBMC enabled PC.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s