On some networks or some mDNS implementations child discovery may not
work well. As an alternative, allow a parent to connect to a device
directly with an IP Address and port.
Some implementations of mDNS on Android display a space as
\\032
and some display it as
\032
Attempt to convert both types to a " " before displaying it
The additional thread to feed the AudioTrack was unnecessary.
Because the AudioTrack API is blocking when data is written,
and internally it buffers data, writing the data as soon
as it is received from the network leads to better playback
performance. It is also much simpler.
The previous approach was to list buttons in a TableLayout.
However, this approach does not work well if there are more
items than can fit on the screen.
To allow scrolling of items, and also a better presentation
of said items, use a ListView.
If the child device disconnects unexpectedly, alert the
user, in case they were not expecting the disconnect.
The audio file being played is originally from here:
https://freesound.org/people/pan14/sounds/263655/
Previously the monitor activity would only support one connection,
after which the activity would need to be restarted. With this change,
if a connection is established with a parent device but is eventually
disconnected the child device will begin advertising again.
Note that because the child device can only support one connection
at a time currently, after the connection is established it will
now stop advertising. When a connection is lost and advertising
starts again, it may end up advertising as another service. E.g.
ProtectBabyMonitor (2)
instead of
ProtectBabyMonitor
If the screen is rotated by default Android destroys the
activity and recreates it. This causes issues if a child and
parent are already paired, as the connection is lost.
To prevent Android from destroying the Activity, instead
invoke a configuration change on an orientation or resize.
If the screen turns off, the child device will be unable to
record from the microphone. Keep the screen on in the monitor
activity to keep microphone on.