I created a SampleMediaRouteProvider as given in https://github.com/googlesamples/android-MediaRouter. In this sample there is also a MediaRouter that discovers all MediaRouteProviders in the network.
This SampleMediaRouteProvider is visible in the same device to other apps but its not visible to apps on other device in the same network.
Can you please help me to get MediaRouteProvider visible in wifi network.
Iam looking to create a MediaRenderer on a Android device that I could use to cast audio from other Android devices.
MediaRouteProvider doesn't really do what you're asking.
The MediaRouteProvider, which you've written, has the role of allowing apps on your phone - device A - to find other devices on the network (device B or C). Device B and C can play the media you have on device A. Device A might stream/mirror directly (say to device B) or 'cast' (say to device C).
When mirroring, you send the audio content out of device A to device B. When casting, you only send a URL to device C, for example, the link to a video on youtube.com. And device C goes directly to the source to get the content.
I think you will need to:
Put your MediaRouteProvider on every device.
Implement a discovery mechanism
for example, based on using SSDP, mDNS, etc.
have your mediarouter implmenent discovery
Implement a webserver on the device(s) with content
or use something like nanohttpd
Now Write your MediaRenderer
Related
Suppose I have two android phones (say Phone A and Phone B). I have paired them through the normal bluetooth pairing procedure. I am developing an app which I will install only on Phone A.
What all data points/events might I be able to get from Phone B through this app by using android bluetooth APIs?
What if instead of Phone B, I have any other bluetooth device that you can think of. What all data points/events might I be able to get?
I'm assuming that my other option could be to build a companion app on Phone B which would talk to the app on Phone A and provide any of the data (say notifications) through providers or accessibility.
Bonus: Any thoughts if Phone B is an iPhone :)
Since nobody has given an answer for this, let me summarize my understanding so far.
When it comes to bluetooth, we can go with some of the predefined bluetooth profiles that are available in the bluetooth standard. We can access any data that is available through the profiles that are supported by the device.
I have a Bluetooth LE Joystick with a couple of buttons. I want to connect it directly to the app without using the Bluetooth Settings, but by connecting to it via BluetoothLeScanner.
I already can connect to a Heart Rate Monitor and get periodic notifications of the HR-values.
I also have created a little temperature/light/humidity sensor with an ESP32 to which I can also connnect and display the sensor values in the app.
My understanding of this HID device may be erroneous. With the help of the App BLE Scanner I can connect to this gadget via BLE and see the offered services.
One of them is 0x1812 HUMAN INTERFACE DEVICE, which contains a couple of characteristics of type REPORT, among others which are described HID OVER GATT PROFILE SPECIFICATION (HOGP_SPEC)
How can I find out which button got pressed, what position the joystick has been moved to? I guess that this has to occur via notifications to which I have to subscribe to.
Is there any Android library avaliable to handle HID input devices? What I do NOT want to do is to use the Bluetooth settings and connect to the device and have it become detected as a HID device and replace the keyboard with some odd mapping. I don't want the OS to get involved at all, just like when I connect and use the HRM and the ESP32.
I couldn't find any information on this.
I can connect to the device with my app, enumerate the services and characteristics. But from there on, I have no clue how to work with HID. Ideally I'd get notifications like "Button A has been pressed" "Joystick got moved to x=32" where x would range from -127 to 127, for example.
Accessing the HID characteristics requires the BLUETOOTH_PRIVILEGED permission since Android 5.0. The only way for an app to obtain that permission is to be signed with the same certificates as system apps.
This is a security feature, to prevent an app from receiving HID events from your keyboard and stealing your passwords.
Quoting from https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/BLE_5F00_on_5F00_Android_5F00_v1.0.1.pdf
4.6 Protected services
Android does not allow to read or write data to the following characteristics (and their descriptors):
HID Service (since Android 5):
a. HID Information
b. Report Map
c. HID Control Point
d. Report
FIDO (https://fidoalliance.org/) (since Android 6)
a. U2F (0000FFFD-0000-1000-8000-00805F9B34FB)
Only applications with BLUETOOTH_PRIVILEGED, that is, applications signed
with the same certificate as the system, are able to read and write
data to those characteristics.
Let's assume I have two androide devices. An AndroidTV and a smartphone.
On both devices I have installed my app, that is capable of video playback streamed from a server.
I want, similar to chromecast, to delegate the playback from my smartphone to the AndroidTV via my app.
How would I do that?
My starting point is this: Media Router here I go for Remote Playback.
If I understand this correctly,
the app on my AndroidTV device would be a MediaRoute Provider,
the app on my phone would use a MediaRoute to launch a CATEGORY_REMOTE_PLAYBACK-intent on the MediaRoute Provider?
This also means, that the callbacks handle all communication, so that I could differentiate via callbacks between passing the url and let the receiver app fetch title and images themself or let it be passed from the sender app?
Or am I on the wrong track?
the app on my AndroidTV device would be a MediaRoute Provider
No. MediaRouteProvider goes on the device that is the user's controller, which in this case would be the phone.
the app on my phone would use a MediaRoute to launch a CATEGORY_REMOTE_PLAYBACK-intent on the MediaRoute Provider?
You can do that. The advantage of using MediaRouteProvider is that any app on that phone that supports RemotePlaybackClient can now support your setup. If you only want your app to do this, you could skip MediaRouteProvider.
Then, either your app or your MediaRouteProvider is responsible for getting the request over to the Android TV device, and your app on it, by some means (WiFiDirect, Bluetooth, GCM over the Internet, whatever). There is nothing in the Android SDK that specifically addresses this -- you're on your own for rolling whatever protocol and connectivity you want. On the plus side, there's no built-in assumption in MediaRouteProvider about any particular way to deliver that information, meaning that you could be connecting to something that is not running Android at all.
There's a way I can send a file to an android device (wich already has my app installed) without paring or the app making the pairing in the background? (Without user intervention)
In my country just few people have data plans in their phones, so I want to create some kind of "server" using a raspberry and a bluetooth dongle so everytime an user with my app it's inside my store, I can show them notifications (with images and text) using the bluetooth connection insted of their cellphone data. (To detect they are in my store I can use geofences or regular beacons)
BLE is not intended to send files with huge size, since it can maximally send 20 byte chunks of data at a time. I'll definately go for the standard Bluetooth protocol if you have a file consisting of a huge size.
The pairing notification depends on how the app has been developed. If you know the device address (MAC address as unique ID) of the remote device beforehand, then you can make a simple "if" statement that checks whether the device address of each discovered device equals the one you have defined. If yes, then you can establish a connection. As a result, the app will automatically establish a connection with the desired device.
I am currently working on the creation of an application for mobile devices with Android which should be capable of sending and receiving messages through local means like wifi and bluetooth. After making a research about it I found out that Android doesn't have a native wifi ad hoc functionality and that the only way to achieve that is through rooting your device and patching the wpa_suplicant and some other similiar methods which are not generic for every device.
Synopsis of what I am trying to achieve:
An application for Android that scans for devices nearby and tries to connect to them automatically. If the other device also got this application isntalled then it automatically accepts any connection request it receives and when the connection is established it sends back a message which ensures that it has this app installed so that both can start exchanging messages automatically and the users don't have to allow/deny any of the sending/receiving in real time.
My questions are:
Is there any way of sending messages through wifi between 2 android
devices without the use of internet?
Since Ad Hoc is not supported, is there any alternative?
In case the answer to 2 is no , then is it possible to make one of
the devices to be an access point so the other can connect to it and
vice versa.
As for bluetooth, is it possible to skip or automate the allow/deny
pop up of an incoming connection and the pairing procedure?
I'll be glad if you could give me an answer to those and/or any suggestions.
You'll be able to communicate between two devices over wifi without a router/access point using Wifi Direct (P2P) in Android 4.0.
Otherwise, I don't believe you can achieve this over Wifi (bluetooth would be the next best alternative). Since 2.2 you can set your phone up to be a Wifi Access Point (for tethering your device's network connection), but during this time, the Wifi hardware is unavailable for normal use. If you had 3 devices it could work (1 AP, 2 connecting to it).
Is this for a constant connection, or a one-off small delivery? You could use NFC if you want to transmit a URL for example (Android Beam integrates this type of sharing in Android 4.0, but could implement it in 2.3).