android - MediaRouter connect second time

Keywords:android 


Question: 

I am using Android's MediaRouter / Presentation API (the support.v7 version).

Everything works fine so far. The only thing that doesn't is:

When I quit my activity (e.g.teardown & remove the callbacks), everything still works fine.

However, when starting this activity (the previous mediarouter-activity was forcefully finished, thus onPause/onDestroy was called FOR SURE => so those callbacks in there are gone too, as also shown in my debug messages) again at some later point in time, the callbacks get created and added and everything. Just, that there is no more onRouteAdded called, only onProviderChanged (With the default provider and thus useless).

It does always work like that (with wifi display [miracast], emulated secondary display, chromecast secondary display..). Are there any resolutions which are not in the examples?

Would you like to look at some code? Which special cases? (Can't post it all..)

I couldn't find anything so far, thanks for your help, in advance.




3 Answers: 

If you change the Google Cast sample app to support MediaRouter.Callback: https://github.com/googlecast/CastPresentation-android

Then I'm getting the onRouteAdded called every time.

 

Using getSelectedRoute()instead of the RouteInfo (which is provided by the callbacks) did the job for me.

MediaRouter.RouteInfo selectedRoute = getHelper().getMediaRouter().getSelectedRoute();
if(provider != null && getCurrentRoute() != null && getCurrentRoute().equals(selectedRoute)){
    Log.d(TAG, "only provider changes, dont do anything");
    return false;
}

if (selectedRoute != null) {
    setCurrentRoute(selectedRoute);
}

return updateContents();

this is definetly weird (as the rest of the code looks exactly as in the provided google android developer samples), but it works.

 

I know this problem was resolved over 1 year ago, but probably it isn't the perfect solution. Maybe it will be useful for somebody else.

I had similar problem with exactly the same symptoms (no more onRouteAdded called). In my situation it was caused by improperly implemented deactivation of MediaRouter: to deactivate it properly you should not only remove all of callbacks, but select default MediaRoute as well.

if (!mMediaRouter.getDefaultRoute().isSelected()) {
    mMediaRouter.getDefaultRoute().select();
}
 

More Articles


c# - Controlling PowerPoint Slideshow

When a slideshow running in PowerPoint I want to control the movement (Next and Previous) of the slides. Of course it is possible with the > and < button on the keyboard, but is there any way in which I can have a custom application listening to the Next and Previous controls?My custom applicatio

.net - PowerPoint Interop - Start presentation with slide index (not fullscreen) with C#

I'm using the code below to start a presentation in C#: var app = new Microsoft.Office.Interop.PowerPoint.Application(); var pres = app.Presentations; Presentation objPres = pres.Open(@"C:\test.pptx", MsoTriState.msoTrue, MsoTriState.msoTrue); objPres.SlideShowSettings.Run();

charts - How to adjust a GraphViz cluster's margin?

I find graphviz cannot independently adjust a cluster's width margin and height margin.As shown below, the cluster's height margin is obviously less than its width margin.GraphViz provides a parameter margin to adjust a cluster's margin. However, it cannot adjust a cluster's width margin only and ke


presentation - Perspective Video inside image

I want to insert a video file (screen recording of an iPhone) inside the image of an actual iPhone but in a perspective view.I found many video-tutorial but all of them are for corner pinning, which doesn't for the images.So my point is to find a way to make corner pinning for the image and then cli

c# - Data presentation in WPF

At the moment, I´m writing a C# - WPF - application, where I often need to show a few Data out of the database. Now, my "problem" is, that I don´t want to use a datagrid, because it is already used very often in my app. Is there any control to show data to the user "beautiful" instead of a datagrid?

r - select certain elements to build incrementally ioslides

I'm building a presentation using ioslides in RStudio. I have a following slide:```{r, echo=FALSE}logo<-"logo.jpg"```## Playing with R<IMG style="position:absolute;top:5.5%;right:5%;width:140px;"SRC="`r logo`">Type in the interactive console:```{r, eval=FALSE}x <- 1:10 # "name <- valu


How to run a Video Presentation on Android in loop?

I have a group of Android Tablets and I need them to only run a Video Presentation as Company Gift Card.The idea of this project is the same of usually Company's Gift PENs, where the Company give to their presentation audience the information in the PEN, but this case we will have on an Android Tabl

r - Line by line analysis and plotting on multiple monitors during presentation

I am preparing a presentation on data analysis and I am provided with a 2-3 monitor and projector head-up. I would like to use one monitor(+projector) for code, one monitor(+projector) for console display and one monitor(+projector) for plots. Monitors are for me, projectors for the audience. I woul

Draw on second Screen using OnGestureDetection and Presentation API in Android?

Currently I have a setup which consists of a Smartphone and a pico-projector connected via MHL. I can send Images to the projector via the Presentation API with no problems. But now I came to the point, where I have to actively manipulate the second screen. I found hardly any information.Basically I

r - Control size of figure in Rstudio presentation

I'm creating a presentation in RStudio (.Rpres). I have a figure that is too large and extends beyond the screen. How can I reduce it?Too big, need to reduce sizeFigure 1========================================================![alt text](fig1)