SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
Desenvolver 
para 
Chromecast
O que é?
O que é?
O que é?
O que NÃO é?
Cenário típico 
Image source: Google Developers webpage
Algumas 
Particularidades 
•mDNS 
•OTA updates automáticos 
•Android / ChromeOS 
•Pairing com PIN / Ultrassons
Google Cast 
É a tecnologia que 
permite criar 
experiências multi-ecrã 
onde o utilizador envia 
e controla o conteúdo. 
Chromecast 
É um dispositivo que implementa 
esta tecnologia!
Existem 2 tipos 
de aplicações 
• Sender Applications 
• Receiver Applications
Sender 
Applications
Android Dev 
Setup 
• Habilitiar desenvolvimento no dispositivo 
• No projecto: 
– Incluir bibliotecas de desenvolvimento 
– Algum boilerplate code 
– Cast Button, Conectividade, ...
Chromecast Dev Mode
Bibliotecas necessárias 
compile 'com.android.support:appcompat-v7:20.0.0' 
compile 'com.android.support:mediarouter-v7:20.0.0' 
compile 'com.google.android.gms:play-services:6.1.11'
AndroidManifest 
<meta-data 
android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version" /> 
android:theme="@style/Theme.AppCompat"
Sender App lifecycle 
Inicializar API 
Descobrir e conectar 
Iniciar Receiver App 
Receber e enviar msgs 
Desconectar
Design Guidelines 
Mais info em: http://goo.gl/NFoHXa
Google Cast Badge 
http://goo.gl/NFoHXa
Google Cast Store
Sender APP code 
The interesting 
parts :)
Inicializar API 
public class MainActivity extends ActionBarActivity 
@Override onCreate() 
// Configure Cast device discovery 
mMediaRouter = MediaRouter.getInstance(getApplicationContext()); 
mMediaRouteSelector = new MediaRouteSelector.Builder() 
.addControlCategory( 
CastMediaControlIntent.categoryForCast(getResources() 
.getString(R.string.app_id))).build(); 
mMediaRouterCallback = new MyMediaRouterCallback(); 
@Override onResume() 
// Start media router discovery 
mMediaRouter.addCallback(mMediaRouteSelector, 
mMediaRouterCallback, 
MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
Cast Button 
<item 
android:id="@+id/menu_item" 
android:title="@string/title" 
app:actionProviderClass="android.support.v7.app. 
MediaRouteActionProvider" 
app:showAsAction="always"/>
Cast Button - Activity 
onCreateOptionsMenu(Menu menu) { 
super.onCreateOptionsMenu(menu); 
getMenuInflater().inflate(R.menu.main, menu); 
MenuItem mediaRouteMenuItem = 
menu.findItem(R.id.media_route_menu_item); 
MediaRouteActionProvider mediaRouteActionProvider = 
(MediaRouteActionProvider) MenuItemCompat 
.getActionProvider(mediaRouteMenuItem); 
// Set the MediaRouteActionProvider selector for device discovery. 
mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector); 
return true; 
}
Comunicação 
class MessagesHub implements MessageReceivedCallback { 
public String getNamespace() { 
return getString(R.string.namespace); 
} 
.... 
GoogleApiClient mApiClient = new GoogleApiClient.Builder(this) 
.addApi(Cast.API, apiOptionsBuilder.build()) 
.addConnectionCallbacks(mConnectionCallbacks) 
.addOnConnectionFailedListener(mConnectionFailedListener) 
.build(); 
mApiClient.connect();
Envio de mensagem 
(Sender App) 
Cast.CastApi.sendMessage(mApiClient, 
mMessageHub.getNamespace(), message) 
.setResultCallback(new ResultCallback<Status>() { 
@Override 
public void onResult(Status result) { 
if (!result.isSuccess()) { 
Log.e(TAG, "Sending message failed"); 
} 
} 
});
Recepção da mensagem 
(Receiver App) 
window.castReceiverManager = 
cast.receiver.CastReceiverManager.getInstance(); 
window.messageBus = 
window.castReceiverManager.getCastMessageBus( 
'urn:x-cast:com.android.lx'); 
window.messageBus.onMessage = function(event) { 
document.getElementById("message").innerHTML= event.data; 
window.castReceiverManager.setApplicationState(text); 
window.messageBus.send(event.senderId, event.data); 
}
MAGIC! 
Sources at: http://goo.gl/xuu9b8
Desligar 
try { 
Cast.CastApi.stopApplication(mApiClient, mSessionId); 
if (mMessageHub != null) { 
Cast.CastApi.removeMessageReceivedCallbacks( 
mApiClient, 
mMessageHub.getNamespace()); 
mMessageHub = null; 
} 
} catch (IOException e) { 
Log.e(TAG, "Exception while removing channel", e); 
} 
mApiClient.disconnect();
Por: Pedro Veloso (http://goo.gl/5y4IZQ) 
Slides disponíveis em : http://goo.gl/0xvjxr

Contenu connexe

Tendances (12)

Ch2 first app
Ch2 first appCh2 first app
Ch2 first app
 
Android Widget
Android WidgetAndroid Widget
Android Widget
 
android level 3
android level 3android level 3
android level 3
 
Chapter 5 - Layouts
Chapter 5 - LayoutsChapter 5 - Layouts
Chapter 5 - Layouts
 
Chapter 10 - Views Part 2
Chapter 10 - Views Part 2Chapter 10 - Views Part 2
Chapter 10 - Views Part 2
 
7 Ways to improve your gradle build
7 Ways to improve your gradle build7 Ways to improve your gradle build
7 Ways to improve your gradle build
 
Android Life Cycle
Android Life CycleAndroid Life Cycle
Android Life Cycle
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 
Gu iintro(java)
Gu iintro(java)Gu iintro(java)
Gu iintro(java)
 
Hierarchy viewer
Hierarchy viewerHierarchy viewer
Hierarchy viewer
 
Android in practice
Android in practiceAndroid in practice
Android in practice
 
Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.Mobile Software Engineering Crash Course - C04 Android Cont.
Mobile Software Engineering Crash Course - C04 Android Cont.
 

Similaire à Develop for Chromecast in 40 Characters

Custom Chromecast Receiver Application
Custom Chromecast Receiver ApplicationCustom Chromecast Receiver Application
Custom Chromecast Receiver ApplicationKurt Mbanje
 
Implementing cast in android
Implementing cast in androidImplementing cast in android
Implementing cast in androidAngelo Rüggeberg
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgetsPrajyot Mainkar
 
Android App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsAndroid App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsDiego Grancini
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgetsSiva Kumar reddy Vasipally
 
What's new in Android O
What's new in Android OWhat's new in Android O
What's new in Android OKirill Rozov
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basicsAnton Narusberg
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...mharkus
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android AppsGil Irizarry
 
Android App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureAndroid App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureVijay Rastogi
 
Session #8 adding magic to your app
Session #8  adding magic to your appSession #8  adding magic to your app
Session #8 adding magic to your appVitali Pekelis
 
Android accessibility for developers and QA
Android accessibility for developers and QAAndroid accessibility for developers and QA
Android accessibility for developers and QATed Drake
 
Android App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAndroid App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAnuchit Chalothorn
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 
What's new in android jakarta gdg (2015-08-26)
What's new in android   jakarta gdg (2015-08-26)What's new in android   jakarta gdg (2015-08-26)
What's new in android jakarta gdg (2015-08-26)Google
 

Similaire à Develop for Chromecast in 40 Characters (20)

Custom Chromecast Receiver Application
Custom Chromecast Receiver ApplicationCustom Chromecast Receiver Application
Custom Chromecast Receiver Application
 
Implementing cast in android
Implementing cast in androidImplementing cast in android
Implementing cast in android
 
Android Froyo
Android FroyoAndroid Froyo
Android Froyo
 
Integrando sua app Android com Chromecast
Integrando sua app Android com ChromecastIntegrando sua app Android com Chromecast
Integrando sua app Android com Chromecast
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgets
 
Android App Development - 14 location, media and notifications
Android App Development - 14 location, media and notificationsAndroid App Development - 14 location, media and notifications
Android App Development - 14 location, media and notifications
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
 
What's new in Android O
What's new in Android OWhat's new in Android O
What's new in Android O
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
Android app development basics
Android app development basicsAndroid app development basics
Android app development basics
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
 
Android App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structureAndroid App development and test environment, Understaing android app structure
Android App development and test environment, Understaing android app structure
 
Session #8 adding magic to your app
Session #8  adding magic to your appSession #8  adding magic to your app
Session #8 adding magic to your app
 
Android
AndroidAndroid
Android
 
Android accessibility for developers and QA
Android accessibility for developers and QAAndroid accessibility for developers and QA
Android accessibility for developers and QA
 
Android programming basics
Android programming basicsAndroid programming basics
Android programming basics
 
Android App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAndroid App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UI
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
What's new in android jakarta gdg (2015-08-26)
What's new in android   jakarta gdg (2015-08-26)What's new in android   jakarta gdg (2015-08-26)
What's new in android jakarta gdg (2015-08-26)
 

Dernier

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Dernier (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

Develop for Chromecast in 40 Characters

  • 6. Cenário típico Image source: Google Developers webpage
  • 7. Algumas Particularidades •mDNS •OTA updates automáticos •Android / ChromeOS •Pairing com PIN / Ultrassons
  • 8. Google Cast É a tecnologia que permite criar experiências multi-ecrã onde o utilizador envia e controla o conteúdo. Chromecast É um dispositivo que implementa esta tecnologia!
  • 9. Existem 2 tipos de aplicações • Sender Applications • Receiver Applications
  • 11. Android Dev Setup • Habilitiar desenvolvimento no dispositivo • No projecto: – Incluir bibliotecas de desenvolvimento – Algum boilerplate code – Cast Button, Conectividade, ...
  • 13. Bibliotecas necessárias compile 'com.android.support:appcompat-v7:20.0.0' compile 'com.android.support:mediarouter-v7:20.0.0' compile 'com.google.android.gms:play-services:6.1.11'
  • 14. AndroidManifest <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> android:theme="@style/Theme.AppCompat"
  • 15. Sender App lifecycle Inicializar API Descobrir e conectar Iniciar Receiver App Receber e enviar msgs Desconectar
  • 16. Design Guidelines Mais info em: http://goo.gl/NFoHXa
  • 17. Google Cast Badge http://goo.gl/NFoHXa
  • 19. Sender APP code The interesting parts :)
  • 20. Inicializar API public class MainActivity extends ActionBarActivity @Override onCreate() // Configure Cast device discovery mMediaRouter = MediaRouter.getInstance(getApplicationContext()); mMediaRouteSelector = new MediaRouteSelector.Builder() .addControlCategory( CastMediaControlIntent.categoryForCast(getResources() .getString(R.string.app_id))).build(); mMediaRouterCallback = new MyMediaRouterCallback(); @Override onResume() // Start media router discovery mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
  • 21. Cast Button <item android:id="@+id/menu_item" android:title="@string/title" app:actionProviderClass="android.support.v7.app. MediaRouteActionProvider" app:showAsAction="always"/>
  • 22. Cast Button - Activity onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.main, menu); MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item); MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat .getActionProvider(mediaRouteMenuItem); // Set the MediaRouteActionProvider selector for device discovery. mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector); return true; }
  • 23. Comunicação class MessagesHub implements MessageReceivedCallback { public String getNamespace() { return getString(R.string.namespace); } .... GoogleApiClient mApiClient = new GoogleApiClient.Builder(this) .addApi(Cast.API, apiOptionsBuilder.build()) .addConnectionCallbacks(mConnectionCallbacks) .addOnConnectionFailedListener(mConnectionFailedListener) .build(); mApiClient.connect();
  • 24. Envio de mensagem (Sender App) Cast.CastApi.sendMessage(mApiClient, mMessageHub.getNamespace(), message) .setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status result) { if (!result.isSuccess()) { Log.e(TAG, "Sending message failed"); } } });
  • 25. Recepção da mensagem (Receiver App) window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance(); window.messageBus = window.castReceiverManager.getCastMessageBus( 'urn:x-cast:com.android.lx'); window.messageBus.onMessage = function(event) { document.getElementById("message").innerHTML= event.data; window.castReceiverManager.setApplicationState(text); window.messageBus.send(event.senderId, event.data); }
  • 26. MAGIC! Sources at: http://goo.gl/xuu9b8
  • 27. Desligar try { Cast.CastApi.stopApplication(mApiClient, mSessionId); if (mMessageHub != null) { Cast.CastApi.removeMessageReceivedCallbacks( mApiClient, mMessageHub.getNamespace()); mMessageHub = null; } } catch (IOException e) { Log.e(TAG, "Exception while removing channel", e); } mApiClient.disconnect();
  • 28. Por: Pedro Veloso (http://goo.gl/5y4IZQ) Slides disponíveis em : http://goo.gl/0xvjxr