Can I connect to the chrome route programmatically?

I am writing an application for receiving chromrest, which (I hope) will allow me to remotely post warning messages on my TV as reminders.

My plan was to set up a wireless device on my home network that constantly requested new messages from a centralized server. When a new message has been detected, it will connect to the chrome path, turn on the TV and display a new message.

But as far as I can tell, the only way to activate the chrome route is to manually click the chrome icon in a Chrome browser or wireless device.

Is there a way to programmatically activate chromite? Can this be done in the sender?

+1
source share
1 answer

You can programmatically scan for cast devices and, if necessary, connect to them. Steps:

  • Get a single-threaded instance of MediaRouter media from the system: mMediaRouter
  • Create a selector: mMediaRouteSelector = new MediaRouteSelector.Builder() .addControlCategory( CastMediaControlIntent .categoryForCast(YOUR_APP_ID)).build();
  • Add a callback to start scanning: mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
  • onRouteAdded() and onRouteRemoved() your callback (i.e. mMediaRouterCallback ) will be called when routes are discovered or deleted. You can maintain a list of routes in your application and update them using these two callbacks.
  • You can select a route by calling mMediaRouter.selectRoute(aRouteInfo) . Then onRouteSelected() your callback is called, and you can retrieve the broadcast device as usual and do as you please.

They said, remember that if you want to show a notification to users on TV, your application should be limp at the time you want to send a notification.

+2
source

Source: https://habr.com/ru/post/1236438/


All Articles