This library allows you to easily create a socket bluetooth connection for two android devices with one server and one client. This library is compatible with the Android SDK 2.3 to 5.1.
Simple implementation with extended BluetoothActivity or FragmentActivity.
public class MainActivity extends BluetoothActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onStart() {
super.onStart();
setTimeDiscoverable(200);
startDiscovery();
}
@Override
public UUID myUUID() {
return UUID.fromString("00001101-0100-1000-8000-00805F9B34FB");
}
@Override
public void onBluetoothStartDiscovery() {
}
@Override
public void onBluetoothDeviceFound(BluetoothDevice device) {
}
@Override
public void onClientConnectionSuccess() {
}
@Override
public void onClientConnectionFail() {
}
@Override
public void onServeurConnectionSuccess() {
}
@Override
public void onServeurConnectionFail() {
}
@Override
public void onBluetoothCommunicator(String messageReceive) {
}
@Override
public void onBluetoothNotAviable() {
}
}
You can also extend your fragment with BluetoothFragment. Don't forget to past the activity result from your activity to your fragment.
You can generate your own UUID on this website
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
The source code to the library and sample application as well as this website is available on GitHub.
If you are using Maven for compilation you can declare the library as a dependency.
<dependencies>
<dependency>
<groupId>com.ramimartin.bluetooth</groupId>
<artifactId>AndroidBluetoothLibrary</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>arissa34-ftp</id>
<name>Arissa Ftp</name>
<url>http://arissa34.free.fr/maven2</url>
</repository>
</repositories>
repositories {
maven {
url "http://arissa34.free.fr/maven2/"
artifactUrls mavenLocal()
}
mavenCentral()
}
dependencies {
compile 'com.ramimartin.bluetooth:AndroidBluetoothLibrary:1.0.1-SNAPSHOT'
}
This library is used in these applications :
Copyright 2015 Rami Martin Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
If you have any questions please feel free to contact me at this email address : rami.34000@gmail.com