palaima / androidsmoothbluetooth Goto Github PK
View Code? Open in Web Editor NEWSmooth communication via bluetooth with other android devices or microcontrollers such as Arduino.
License: Apache License 2.0
Smooth communication via bluetooth with other android devices or microcontrollers such as Arduino.
License: Apache License 2.0
Not always do we want to let the device connect to just any device found around.
Most of the applications would need to connect to specific devices around, may it be user's choice or preconfigured to control one specific device.
Hello sir, I am very new to android and I tried using your library. After selecting the desired bluetooth device I am getting the same result "Failed to connect to device". as shown in your documentation, I also tried to connect to an android phone by setting connectionto.Android devices in the constructor, but all in vain. Can you please help?
Hi,
i use this library, but i need help with one question. I must connect to device, but i need send paired code.
How i can send paired code in connectionTo(device)?
Error:(223, 21) error: method adapter in class Builder cannot be applied to given types;
required: ListAdapter,ListCallback
found: DevicesAdapter
reason: actual and formal argument lists differ in length
I have 2 paired Android devices, and I have this code:
mSmoothBluetooth = new SmoothBluetooth(this, SmoothBluetooth.ConnectionTo.ANDROID_DEVICE, SmoothBluetooth.Connection.SECURE, mListener); mSmoothBluetooth.tryConnection(); private SmoothBluetooth.Listener mListener = new SmoothBluetooth.Listener() { @Override public void onBluetoothNotSupported() { //device does not support bluetooth } @Override public void onBluetoothNotEnabled() { //bluetooth is disabled, probably call Intent request to enable bluetooth } @Override public void onConnecting(Device device) { //called when connecting to particular device Log.w("DEBUG","Connecting to device "+device.getName()); } @Override public void onConnected(Device device) { //called when connected to particular device Log.w("DEBUG","Connected device "+device.getName()); } @Override public void onDisconnected() { //called when disconnected from device } @Override public void onConnectionFailed(Device device) { //called when connection failed to particular device Log.w("DEBUG","Connection failed to device "+device.getName()); } @Override public void onDiscoveryStarted() { //called when discovery is started } @Override public void onDiscoveryFinished() { //called when discovery is finished } @Override public void onNoDevicesFound() { //called when no devices found } @Override public void onDevicesFound(List list, SmoothBluetooth.ConnectionCallback connectionCallback) { Log.w("DEBUG","Found devices"); if(list.size()==1) { Log.w("DEBUG", "Found 1 device"); Log.w("DEBUG", "Device is paired: "+list.get(0).isPaired()); connectionCallback.connectTo(list.get(0)); } } @Override public void onDataReceived(int data) { //receives all bytes } };
I always get this log:
D/BluetoothManager? Paired devices: 1 W/DEBUG? Found devices W/DEBUG? Found 1 device W/DEBUG? Device is paired: true W/DEBUG? Connecting to device GT-S5830i D/BluetoothService? setState() 0 -> 1 D/BluetoothService? setState() 1 -> 2 D/BluetoothService? setState() 2 -> 1 W/DEBUG? Connection failed to device GT-S5830i
Why does the connection fail if they are paired already?
Use it in this way might solve the issue.
new MaterialDialog.Builder(this)
.title(R.string.socialNetworks)
// second parameter is an optional layout manager. Must be a LinearLayoutManager or GridLayoutManager.
.adapter(new ButtonItemAdapter(this, R.array.socialNetworks), null)
.show();
I read your source code to understand why it does not connect smoothly and I found that no BluetoothService is avalaible before you call connect(), but for the case of a server you don't have to need to search and try to pair to another device. The client has to connect to the server.
Example : device1 is my server, device2 is my client. Device1 is visible, device2 tries to connect to device1 but it fails. We can repeat this operation several times it will always fail. But if device1 tries to connect to device2 it will work because both have called connect(), so both have already a BluetoothService instance.
My solution is to add these lines
if (!isServiceAvailable()) {
setupService();
}
startService(mIsAndroid, mIsSecure);
in the end of the constructor, and it works correctly (I already tested it).
Hope it will help
LAcrym0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.