Comments (2)
Can you post the full code snippet you're trying to use?
from simplebluetoothlibrary.
I copy simplebluetooth class on readme.md to a new project
import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.devpaul.bluetoothutillib.SimpleBluetooth;
import com.devpaul.bluetoothutillib.dialogs.DeviceDialog;
import com.devpaul.bluetoothutillib.utils.SimpleBluetoothListener;
import com.example.testblue.R;
public class MainActivity extends Activity {
private SimpleBluetooth simpleBluetooth;
private static final int SCAN_REQUEST = 119;
private static final int CHOOSE_SERVER_REQUEST = 120;
//...other code....//
private String curMacAddress;
@Override
protected void onResume() {
super.onResume();
simpleBluetooth = new SimpleBluetooth(this, new SimpleBluetoothListener() {
@Override
public void onBluetoothDataReceived(byte[] bytes, String data) {
//read the data coming in.
}
@Override
public void onDeviceConnected(BluetoothDevice device) {
//a device is connected so you can now send stuff to it
}
@Override
public void onDeviceDisconnected(BluetoothDevice device) {
// device was disconnected so connect it again?
}
@Override
public void onDiscoveryStarted() {
}
@Override
public void onDiscoveryFinished() {
}
});
simpleBluetooth.initializeSimpleBluetooth();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//...other code...//
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
} else if (id == R.id.scan) {
simpleBluetooth.scan(SCAN_REQUEST);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == SCAN_REQUEST || requestCode == CHOOSE_SERVER_REQUEST) {
if(resultCode == RESULT_OK) {
curMacAddress = data.getStringExtra(DeviceDialog.DEVICE_DIALOG_DEVICE_ADDRESS_EXTRA);
if(requestCode == SCAN_REQUEST) {
simpleBluetooth.connectToBluetoothDevice(curMacAddress);
} else {
simpleBluetooth.connectToBluetoothServer(curMacAddress);
}
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
simpleBluetooth.endSimpleBluetooth();
}
}
from simplebluetoothlibrary.
Related Issues (20)
- Issue with Device to Device Communication HOT 8
- Switch to JitPack.io HOT 1
- Add support for minimum SDK 14 HOT 4
- Receiving partial data from Arduino HOT 10
- device not avaible error HOT 2
- Add Marshmallow support HOT 2
- Unable to send to Arduino HOT 3
- Create new sendData(byte[] bytes) method HOT 3
- Silent enableBluetooth() method HOT 6
- Initialize with flag to disable toast messages HOT 8
- Update support library 23.2.0 HOT 6
- incomplete data HOT 11
- Data not complete HOT 40
- BluetoothUtility.closeConnections() crashes HOT 3
- Update to latest libs HOT 1
- Nexus 5 doesn't scan any devices HOT 2
- can i use this library to read Glucose reading device , HOT 3
- Data Lossed with arduino HOT 6
- failed to resolve: com.afollestad.material-dialogs:core:0.8.5.6 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simplebluetoothlibrary.