Reputation: 45108
Is it possible to detect if there are any Chromecast devices on the current WiFi network. I've seen that there's a Cast SDK but I couldn't find anything about searching for devices. Having never worked with this SDK before, it is possible that I may have overlooked it.
Upvotes: 7
Views: 7052
Reputation: 31
A very simple solution is to use com.youview.tinydnssd.DiscoverResolver
. Here my implementation:
DiscoverResolver resolver = new DiscoverResolver(ctx, "_googlecast._tcp.", new DiscoverResolverHandler());
In DiscoverResolverHandler()
you can handle the result.
Upvotes: 0
Reputation: 1113
You can use SSDP (Simple Service Discovery Protocol) in your local network with an ST (Service Type) of:
urn:dial-multiscreen-org:service:dial:1
Your SSDP Query should look like this:
M-SEARCH * HTTP/1.1\r\n
Host: 239.255.255.250:1900\r\n
MAN: "ssdp:discover"\r\n
MX: 3\r\n
ST: urn:dial-multiscreen-org:service:dial:1\r\n\r\n
You will get a list of all devices (IP and Port) that support those service type (like Chromecast does). Then you could pull a xml file from this IP:8008 to check if it really is a Chromecast device:
http://IP:8008/ssdp/device-desc.xml
The Response will look like this:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<URLBase>http://192.168.0.0:8008</URLBase>
<device>
<deviceType>urn:dial-multiscreen-org:device:dial:1</deviceType>
<friendlyName>Chromecast</friendlyName>
<manufacturer>Google Inc.</manufacturer>
<modelName>Eureka Dongle</modelName>
<UDN>uuid:3c7f2a1e-dbd2-f94d-b456-816555a9d1f9</UDN>
<iconList>
<icon>
<mimetype>image/png</mimetype>
<width>98</width>
<height>55</height>
<depth>32</depth>
<url>/setup/icon.png</url>
</icon>
</iconList>
<serviceList>
<service>
<serviceType>urn:dial-multiscreen-org:service:dial:1</serviceType>
<serviceId>urn:dial-multiscreen-org:serviceId:dial</serviceId>
<controlURL>/ssdp/notfound</controlURL>
<eventSubURL>/ssdp/notfound</eventSubURL>
<SCPDURL>/ssdp/notfound</SCPDURL>
</service>
</serviceList>
</device>
</root>
More info about it here: http://wolfpaulus.com/jounal/mac/chromecasting/
If you want to stream something to your Chromecast, you can get information about the ChromeCast App by calling:
http://IP:8008/apps/ChromeCast
Upvotes: 3
Reputation: 19094
You can perform discovery without using the cast button; you need to use media router from v7 support library (which needs the v7 appcompat support as well) and then get an instance of the media router from your code, define a selector (which is basically a filter to possibly narrow down the devices that you are interested in) and then add a callback to start discovery. As devices are discovered (asynchronously), your callbacks will be called. Take a look at this sample project, specially this class which does exactly what you want.
Upvotes: 3
Reputation: 5694
Following the recommended way of Google
you don't need to scan for Chromecast
devices to provide content from an Android
app. You can add a cast button to your Activity
by extending it with ActionBarActivity
and then adding in onCreateOptionsMenu() an ActionBar
option item with
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
as action.
Here you can find a complete sample on how to send to a Chromecast
stick. If you want to scan manually for any reason, you can use the Android
MediaRouters
API, quote from the docs:
Cast device discovery may be performed using the Android MediaRouter APIs in the Android Support Library, with compatibility back to Android 2.1.
Upvotes: 0
Reputation: 59826
Chromecast devices are discoverable using avahi with the type _googlecast._tcp
$ avahi-browse -r _googlecast._tcp
+ eth0 IPv4 Living Room _googlecast._tcp local
= eth0 IPv4 Living Room _googlecast._tcp local
hostname = [Living\032Room.local]
address = [192.168.1.100]
port = [8009]
txt = ["st=0" "fn=Living Room" "ca=5" "ic=/setup/icon.png" "md=Chromecast" "ve=02" "id=c832a30b81ab84a706c82745438fcd64"]
Upvotes: 6