The Android peer-to-peer sync library is a library/component that enables apps to easily share their records/data with other devices when offline. The library supports 1-to-1 connection and the app can receive record/data updates from another app. This main purpose is to support data reporting up the administration hierarchy after it is collected on the ground where internet connection is scarce but administration has access to internet. It can also be used in many other device-to-device share use-cases
The library uses a couple of technologies worth mentioning:
Google Nearby Connections API is a peer-to-peer networking API that allows discovery, connection and data exchange in real-time regardless of network connectivity. This library provides the following in the library:
The API uses a combination of Bluetooth, BLE(Bluetooth Low Energy) and Wifi hotspots to perform the functions above. Thus the following technologies are required on the devices for effective and optimal functioning of the library.
Location is required to be turned on and the user requires to accept the Location permissions so that the app can turn this on for you. If location permission is denied, then the library will not be able to work.
This library enables secure storage of transfer history so that updates can be retrieved from other devices.
This API is provided by Google and provides QR code scanning capabilities on all camera-enabled devices. This capability is required for confirming the connecting device during connection-initiation.
This feature may not work if your Google Play Store application is not up-to-date. In such a case, kindly connect to the internet and try to open the Play Store application on the affected device. This should prompt the Play Store application to update following the required Mobile Vision API.
The aim of this library is to provide the following functionality:
The following are some of the issues and how to fix them:
Detailed and updated instructions on how to add it in your Android project can be found here. For use in OpenSRP clients, below is the guide on how to integrate it.
This library has already been integrated into OpenSRP Client Core library and currently supports sharing events, clients and profile images. The default authorization implemented for OpenSRP Client Core makes sure that both the sender and receiver are in the same team by:
To add more authorization conditions, you can override this authorization service or implement your own from interface provided by the library. The authorization service is configurable when setting up the CoreLibrary.
To use the library in an OpenSRP client application,
maven {
url "https://s3.amazonaws.com/repo.commonsware.com"
}
P2POptions
as below when initializing the CoreLibrary:
P2POptions p2POptions = new P2POptions(true);
// Add the optional configurations to the P2POptions
p2POptions.setAuthorizationService(new ChwAuthorizationService());
CoreLibrary.init(context,
new
ChwSyncConfiguration(), BuildConfig.BUILD_TIMESTAMP, p2pOptions);