I am trying to get my Media Route Selector to show both MiraCast and Chromecast devices. I have a Chromecast receiver app and also make use of the Presentation API in Android so ideally the user should only have to click the media router button and chose the device they have without even having to think about it. I was following this guide (https://developer.android.com/guide/topics/media/mediarouter.html#selector) to achieve this and in the picture it shows both a Chromecast and wireless display available in the route selector. However, after adding the control categories I still only see the Chromecast.
Here is the relevant code.
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
.addControlCategory(CastMediaControlIntent.categoryForCast(CAST_APP_ID))
.build();
...
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
I have tried changing the callback flag also but saw no change.
EDIT:
I ended up creating a custom dialog factory for the router button and using a separate layout that includes a button that will send the user to wireless display settings. Not exactly the solution I was looking for but it appears that what I was actually trying to do is not supported.
Related
I have seen that in Apple watches, when the watch has been disconnected from the iPhone, in the watch apps, there is an icon in the top center that shows that the watch has been disconnected.
Is there anything similar in Wear OS?
Some kind of OS level icon that can be implemented easily, similar to how I could use TimeText() in Compose to show the OS time without having to handle it myself?
Or is my only option to use the Bluetooth manager to check for connections, and show a custom icon myself based on that?
I tried putting my Wear OS device on airplane mode. This shows a disconnection icon in the watch face. I would like to show that icon in the app. There seems to be no official documentation on this topic, so perhaps it is not possible?
No OS level facility. Instead of using the BluetoothManager, you can subscribe to the NetworkManager, and then show whether you are connected to the paired mobile, or possibly have a Wifi/LTE network.
val networkRequest = NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
.addTransportType(NetworkCapabilities.TRANSPORT_BLUETOOTH)
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build()
connectivityManager.registerNetworkCallback(networkRequest, networkCallback)
The TimeText component is extensible, so you can add leading content like is done here.
https://github.com/google/horologist/blob/fe6ee111501b05fbd1d33dd1bdd9fe87333c4477/network-awareness/src/main/java/com/google/android/horologist/networks/ui/DataUsageTimeText.kt#L4
Android 29 has dropped the ability to programatically enable/disable the phone's Wi-Fi interface. An application I work on connects to an external wi-fi device (p2p, no outbound internet) programatically. If wi-fi is not enabled, we ask the user to enable it.
There is a new system UI Panel API documented here. We can show a basic toggle switch to the user to enable wi-fi via this:
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
Once Wi-Fi is enabled we connect via the process described below:
Eg:
val ssid = ssidObtainedExternally()
val psk = pskObtainedExternally()
val specifier = WifiNetworkSpecifier.Builder()
.setSsid(ssid)
.setWpa2Passphrase(psk)
.build()
val request = NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.setNetworkSpecifier(specifier)
.build()
connectivityManager.requestNetwork(request, networkCallback)
However, one issue with this is that after the user switches the toggle to enabled, the same dialog will then start showing a list of available Wi-Fi networks which may entice the customer to choose the wi-fi device (since the SSID is just the name of the device, which they know). Since we will programmatically connect, we don't want the user to try and manually select the wi-fi network since they won't know the PSK. It would be ideal to dismiss the dialog as soon as they toggle the switch to enable.
I tested this with the GoPro 8 and that app seems to have a mechanism to dismiss the dialog once the user toggles the switch.
I've tried a few things so far with no luck. I tried using Application.registerActivityLifecycleCallbacks but it doesn't pick up the settings panel being created, started, or resumed.
I also tried the tip here: https://stackoverflow.com/a/32929066/94557
With no luck (the only visible activities were ones declared in my app that were in the stack)
Any ideas?
It looks like I've found a hack that seems to work and is probably what the gopro app does. The idea is to keep a reference to your current activity after you launch the Wifi settings panel. Once you detect that Wifi is enabled, call
yourPreviousActivity.startActivity(yourPreviousActivityIntent)
with an intent that represents the screen you were on previously. You will want to add the following flag to the intent:
FLAG_ACTIVITY_CLEAR_TOP
The end result is your activity is re-launched and the settings panel is hidden.
If you have any animation runs on open you will want to disable it.
I am writing an Android application which detects DLNA and Chrome devices. Application design language does not support putting cast button on ActionBar. Instead I need to poll the DLNA and Chrome devices and display in a list.
The code written for detecting cast devices is as follows:
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent.categoryForCast(CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID))
.build();
mMediaRouterCallback = new MyMediaRouterCallback();
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
Using the above code, I have trouble detecting the chrome devices. I takes ~10 minutes for the devices that are in the network to get detected. Sometimes it takes even more time. But using CastButton in the Actionbar, the devices are detected immediately.
How to detect the chrome devices without any latency?
I suggest you call mMediaRouter.getRoutes() and then rely on the callback to stay up-to-date as routes come and go. It may be the case that MediaRouter has already discovered your devices and depending on a number of factors, your callback may not receive a notification for such routes. If you see that in those cases mMediaRouter.getRoutes() has what you want, then you would need to filter the routes obtained by that call manually (using the same selector and RouteInfo.matchesSelector(selector).
I know that the Chromecast is being launched automatically with any app that has the "Cast" icon. That means we can be using directly a phone or tablet without the TV controller to initiate a connection.
HDMI-CEC has something to do with this.
TV switches automatically.
What I would like to know is if it would be possible to end the connection with the Chromecast and not land on the Chromecast homepage like right now. I would like to come back on the signal that I had before the "Cast", which could be a channel of the TV for example, and this, without the TV controller.
Currently, it is impossible to come back without not using the "Source" button of the TV controller.
Does anyone have a solution that could help me?
So, in CEC there is a provision to tell the TV you're done. It's called <Inactive Source>.
Chromecast uses <Active Source> to turn on the TV and change inputs it it.
It could use <Inactive Source> to indicate to the TV that it has stopped sending video.
<Inactive Source>, however, varies by TV.
These days , i implement a blue tooth paring function on android platform,say in details:
The master device is Google TV(3.2), the slave device is blue tooth keyboard,both are HID device.
The Keyboard can be easily put in to discoverable status, When the TV bootup first time ,In TV setup guide, i need to let the tv paring with keyboard,
As you know, in generall, enable bluetooth on TV side we need get the user permition, then can connect.Then my question happend is that i don't want to pop up a dialog to get permition, is there some body can tell me how to do ?
Thanks!
I found a simple way - in the Android code tree, in external\bluetooth\bluez\src\device.c:
/* If our IO capability is NoInputNoOutput use medium security
* level (i.e. don't require MITM protection) else use high
* security level */
if (capability == 0x03)
sec_level = BT_IO_SEC_MEDIUM;
else
sec_level = BT_IO_SEC_HIGH;
//david10000 add
if (device_is_david10000_BTDEV(device)) {
sec_level = BT_IO_SEC_MEDIUM;
}
This means we can low level the security to let your special device connect automatically.
Another way is you can program it to auto fill the passkey/pin etc. when you get the Android pair request.
If you have this problem, try this, it works for me.