Adaptive Communication Framework for Android Devices using Bluetooth and Bluetooth Low Energy
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
Getting Started
Prerequisites
The first step is to add the following permissions in AndroidManifest.xml
:
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Meshify supports both Bluetooth Classic and Bluetooth Low Energy (BLE) capable devices.
If you only planning to use BLE, you can optionally declare that your app uses BLE features on Android devices. By doing so, users on devices without BLE capabilities won’t see your app on the Google Play Store. If this behavior sounds good to you, add the following snippet below the <uses-permission>
tags.
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true" />
Usage
Multiple methods can be used to integrate the Meshify framework in an Android project.
- First method is to download the source code from the git repository and include it directly as a project-level dependency using Gradle. Here, the developer can modify the source code if that is required.
implementation project(path: ':meshify')
- Another option is to download the Android Archive (AAR) of the framework and integrate it into the project using Gradle.
implementation files("libs/meshify.aar")
Initialization
You need to create a UUID
include that in your AndroidManifest.xml
file. This will be used to uniquely identify your application.
<meta-data
android:name="com.codewizards.meshify.APP_KEY"
android:value="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />
Starting Meshify
Call the Meshify.initialize(...)
method of Meshify.
Meshify.initialize(getApplicationContext());
ConnectionListener
You can either implement ConnectionListener
interface or create an Anonymous Class
of ConnectionListener
.
// Anonymous Class
ConnectionListener connectionListener = new ConnectionListener() {
@override
public void onStarted() {
}
@override
public void onStartError(String message, int errorCode); {
}
@override
public void onDeviceDiscovered(Device device) {
}
@override
public void onDeviceConnected(Device device, Session session) {
}
public void onIndirectDeviceFound(Device device){
}
@override
public void onDeviceLost(Device device) {
}
}
MessageListener
You can either implement MessageListener
interface or create an Anonymous Class
of MessageListener
.
// Anonymous Class
MessageListener MessageListener = new MessageListener() {
@override
public void onMessageReceived(Message message) {
}
@override
public void onBroadcastMessageReceived(Message message) {
}
@override
public void onMessageFailed(Message message, MessageException exception) {
}
@override
public void onMessageSent(Message message) {
}
}
Configuration
You can customize the Meshify
framework according to your requirement using Config
Builder.
Config.Builder builder = new Config.Builder();
builder.setNeighborDiscovery(true);
builder.setAutoConnect(true);
and finally call Meshify.start()
to start the meshify service.
Meshify.start(messageListener, connectionListener, builder.build());