SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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.
 

Ähnlich wie 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
 

Ähnlich wie 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)
 

Kürzlich hochgeladen

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

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