React Native broadcast and discover nearby devices - android

First off: This is more of a logical question than a code-specific question.
I am trying to create a view similar to the iOS AirDrop view where users can see other users. This means, every user needs to broadcast/advertise their custom username, which can be seen by all other nearby users that scan the area.
I have tried using react-native-ble-plx, since I read on the Apple developer forum that iPhones can act as BLE (bluetooth low energy) peripherals. (Also, I read that newer Android devices support this as well)
I've tried the following:
import ble, { BleManager, Characteristic } from 'react-native-ble-plx';
// ...
const bleManager = new BleManager();
bleManager.startDeviceScan(null, null, async (e, d) => {
if (e) console.log(`BT Error: ${JSON.stringify(e)}`);
if (d && d.id && d.isConnectable) {
console.log(`Connecting to: ${d.id} ('${d.name}')...`);
const device = await d.connect();
const services = await device.services();
console.log('services: ', services.join(', '));
const characteristic = await device.writeCharacteristicWithResponseForService(BLE_SERVICE_UUID, BLE_SERVICE_UUID, '123');
console.log(`Characteristics: ${JSON.stringify(characteristic)}`);
}
});
But I haven't found a way to broadcast a value which others can read, is that even possible with BLE?
I've also looked into beacons (specifically react-native-beacons-manager), but I'm not sure if that is what I want since an Android/iOS phone is not a 'beacon'..
So my question is: Are there technologies/libraries that allow broadcasting of a message (my custom username) which others can see? Ideally I want to communicate between them, like exchanging a token, but that's not a requirement.
I'd appreciate any help or pointings into the right direction here, thanks!

I managed to get it working after really long debugging nights.
It is possible using the Google Nearby Messages API, and setting it to use .BLE only.
I've created an open source react native module for this here: https://github.com/mrousavy/react-native-google-nearby-messages

Related

Using BLE shutter remote to control React Native app

Is it possible to detect when a button has been pressed on a BLE HID device using react-native-ble-plx?
I want to use these BLE remotes to have a cheap and robust way of controlling a React Native app with external devices (avoiding making a new project using ESP32 or it's variants would be preferred). When connected through the Android OS it works as simple volume up and volume down buttons - which triggers camera shutter, as intended. However, when connected to a BLE app (tested with LightBlue and with a React native app) that functionality is gone.
I have a few of these remotes and need to detect when a button was pressed and which remote was pressed on. Because they are BLE and not Bluetooth classic more than one can be connected at the same time.
Detection of volume up and volume down actions works by using react-native-keyevent but only when the remotes are connected to the OS and there is no way to get which remote triggered the action.
By using this piece of code to try to monitor all characteristics only errors are returned:
await bleManager.connect(discoveredDevice);
let discoveredServices = (await (await discoveredDevice.discoverAllServicesAndCharacteristics()).services());
for (let iService = 0; iService < discoveredServices.length; iService++) {
let characteristics = await discoveredServices[iService].characteristics();
for (let iCharacteristic = 0; iCharacteristic < characteristics.length; iCharacteristic++) {
characteristics[iCharacteristic].monitor((error: BleError | null, characteristic: Characteristic | null): void => {
if (error) {
console.error(error.message);
return;
} else {
console.log(characteristic?.value);
}
});
}
}
The following error occurs for all monitor() calls - with different UUIDs:
ERROR Characteristic 0000ae42-0000-1000-8000-00805f9b34fb notify change failed for device ? and service 0000ae40-0000-1000-8000-00805f9b34fb
A screenshot containing the services and characteristics of the device captured within LightBlue can be found here
This question might be duplicate of this question

is it possible to recognize wifi network inside app with xamarin

I'm just wondering if it's possible for an app to recognize what network you are connected to. I'm making and app where you have to be connected to a specific network before the app lets you use it's functions, but I'm wondering if that is even possible, I am using xamarin but I can program with androidand a little bit ofswift, so I also want to know if it's possible forxamarinto do this, if it's possible with android studio andxcode. I am usingxamarin.forms` by the way.
This used to be disabled for security reasons but after iOS 4.0 Apple enabled it.
Although this question is for Xcode, the answer can be applied in Xamarin.
This is a sample application built with the feature in question, although it is for Xamarin.Mac
Use function CNCopyCurrentNetworkInfo.
This is possible but you will have to do native implementations to access the specific platform apis. For Android you will need to use WifiManager (https://developer.android.com/reference/android/net/wifi/WifiManager) and for iOS you could possibly use NEHotspotConfiguration (https://developer.apple.com/documentation/networkextension/nehotspotconfiguration).
I have used WifiManager for Android to connect to a specific Wifi network programmatically.
You can use "CrossConnectivity" plugin in Xamarin by adding the package "xam.plugin.connectivity". Below is the code to check connectivity. From the connectionType property you can detect to which network the device is connected and perform operations accordingly. `
CrossConnectivity.Current.ConnectivityTypeChanged += (sender, e) =>
{
var wifi = Plugin.Connectivity.Abstractions.ConnectionType.WiFi;
var cellular = Plugin.Connectivity.Abstractions.ConnectionType.Cellular;
var connectionTypes = CrossConnectivity.Current.ConnectionTypes;
if (connectionTypes.Contains(cellular))
{
//Do operations with cellular
}
else if (connectionTypes.Contains(wifi))
{
//Do operations with wifi
}
};`

Connecting iOS and Android devices using a WiFi with no internet connection

I have a really huge place in which what I need is that people can chat with each other. I would place WiFi router to cover the whole place but, due to the high amount of people, I can't provide an internet connection through that network. Which technology should I use? I've been reading about AllJoyn but I don't know if that would help me. Also, because of the amount of people (over 75,000) I can't setup a server to handle the service, per connection, 1 devices will have to be the host and the other one will have to be the client. Thanks
If you want to create your own application you could use something like Signalr and Xamarin using their SignalR component.
Taken from the Quick Usage on the component page:
// Connect to the server
var hubConnection = new HubConnection("http://server.com/");
// Create a proxy to the 'ChatHub' SignalR Hub
var chatHubProxy = hubConnection.CreateHubProxy("ChatHub");
// Wire up a handler for the 'UpdateChatMessage' for the server
// to be called on our client
chatHubProxy.On<string>("UpdateChatMessage", message =>
text.Text += string.Format("Received Msg: {0}\r\n", message));
// Start the connection
await hubConnection.Start();
// Invoke the 'UpdateNick' method on the server
await chatHubProxy.Invoke("UpdateNick", "JohnDoe");
Alternatively there are applications out there that likely do what you want already. For example http://beebeep.sourceforge.net/

UUID of Alert Notification Profile - ANP (in GATT), in Bluetooth Low Energy

I am working with Alert Notification Profile (ANP) in Bluetooth Low Energy between Samsung Galaxy S3 and peripheral device.
I can not find any information related to specific UUID's ANP at Android Developer Site.
But in ANCS Specifications (iOS Developer Site), They define specific UUID's ANCS :
The Apple Notification Center Service is a primary service whose service UUID is 7905F431-B5CE-4E99-A40F-4B1E122D00D0.
I feel worry about this different, so anyone can tell me about :
What is specific UUID's ANP in Android?
P/s : From UUID in Wiki, I know this :
Anyone can create a UUID and use it to identify something with reasonable confidence that the same identifier will never be unintentionally created by anyone to identify something else.
But actually, Google Developer has not confirmed about specific UUID's ANP yet?
The basic Bluetooth is : 0000xxxx-0000-1000-8000-00805f9b34fb.
"xxxx" is Assigned Number you need replace in it, you can declared.
But the other thing, at firmware side also define that UUID for Mobile Application can communicate with Firmware.
You dont need to know the uuid of profile. You need to know the uuids of services belong to this profile. It has one services and the uuid is 00001811-0000-1000-8000-00805f9b34fb
Also yoou need to know the uuids characteristics belong to this services to get the value of them. It has 5 characteristics:
1- New Alert Category : 00002A47-0000-1000-8000-00805f9b34fb
2- New Alert : 00002A46-0000-1000-8000-00805f9b34fb
3- Supported Unread Alert Category : 00002A48-0000-1000-8000-00805f9b34fb
etc..
I guess you are trying to use the Phone to send Alert to an external device ?
If I understand correctly the bluetooth specs, https://developer.bluetooth.org/TechnologyOverview/Pages/ANS.aspx , your Phone is supposed to be turned into a peripheral, not a central to do that.
Peripheral = slave, server
central = master, client
The issue is, android phones can't be turned into peripherals (so far) https://code.google.com/p/android/issues/detail?id=59693
While it is probable that a future update fixes this, it is not an available feature yet.
Of course you could always hack your way into making it available ;-) but that'd be a dirty solution http://blog.cozybit.com/enabling-peripheral-mode-in-android-kitkat-4-4/

Detecting another nearby android device via Bluetooth

Alright, I've got a bit of a weird question here. I'm working on an Android game where I'd like to be able to have Android phones detect the presence of each other.
The device searching for other players will know the bluetooth mac addresses of the other players' devices (from a game DB), however the devices will not be paired and the devices will not be in discoverable mode. Also, there will only be a handful of devices that could possibly be found - so it's not a big deal to scan through mac addresses.
I don't need to connect to the devices, I just need to be able to answer one simple question: is this device with this mac address nearby?
It is permissible to have a pairing dialog appear on the other user's screen...I don't care what the outcome of their choice is...I just need to know if their device is there.
Any help would be greatly appreciated!
This use-case may be a good fit for the recently released Nearby API. See the Nearby Messages developer overview
Nearby has its own runtime permission saving you from adding BLUETOOTH_ADMIN or similar to your manifest. It works across iOS and Android by utilizing multiple technologies (Classic Bluetooth, BLE, ultrasound). There's an option to use only the ultrasonic modem which reduces the range to about 5 feet.
I've included a partial example below, you can find a more complete sample on github
// Call this when the user clicks "find players" or similar
// In the ResultCallback you'll want to trigger the permission
// dialog
Nearby.Messages.getPermissionStatus(client)
.setResultCallback(new ResultCallback<Status>() {
public void onResult(Status status) {
// Request Nearby runtime permission if missing
// ... see github sample for details
// If you already have the Nearby permission,
// call publishAndSubscribe()
}
});
void publishAndSubscribe() {
// You can put whatever you want in the message up to a modest
// size limit (currently 100KB). Smaller will be faster, though.
Message msg = "your device identifier/MAC/etc.".getBytes();
Nearby.Messages.publish(googleApiClient, msg)
.setResultCallback(...);
MessageListener listener = new MessageListener() {
public void onFound(Message msg) {
Log.i(TAG, "You found another device " + new String(msg));
}
});
Nearby.Messages.subscribe(googleApiClient, listener)
.setResultCallback(...);
}
Disclaimer I work on the Nearby API

Categories

Resources