Bluetooth 4.0 BLE Development

Bluetooth 4.0 BLE Development

Source code introduction: Integrate the current mainstream Bluetooth demo

Source code effect:

Source code snippet:

  1. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
  2. mBluetoothAdapter = bluetoothManager.getAdapter();
  3.    
  4. // Checks if Bluetooth is supported on the device.  
  5. if (mBluetoothAdapter == null ) {
  6. Toast.makeText( this , R.string.error_bluetooth_not_supported,
  7. Toast.LENGTH_SHORT).show();
  8. finish();
  9. return ;
  10. }
  11. // Turn on Bluetooth  
  12. mBluetoothAdapter.enable();
  13.    
  14. mBLE = new BluetoothLeClass( this );
  15. if (!mBLE.initialize()) {
  16. Log.e(TAG, "Unable to initialize Bluetooth" );
  17. finish();
  18. }
  19. // Callback when the BLE terminal's Service is discovered  
  20. mBLE.setOnServiceDiscoverListener(mOnServiceDiscover);
  21. // Receive the event of BLE terminal data interaction  
  22. mBLE.setOnDataAvailableListener(mOnDataAvailable);

Download address: http://download..com/data/2096560

<<:  Behind the rumors of Google entering China: the market structure has been determined or it may not adapt to the local environment

>>:  Photo browsing artifact source code sharing

Recommend

22 Lectures of Go Language Evangelist's Getting Started Notes

Go has become the most competitive programming la...

4 Tips for Analyzing Peers in SEO!

1. Visit the competitor's website as a visito...

iOS 16.4 quasi-official version released, new features and changes

Early this morning, Apple pushed the iOS 16.4 RC ...

Your cat is staring at you, does it actually want to eat you?

In the process of getting along with their cats, ...

Little Fox's Minimalist Butt Lifting Course

Introduction to Little Fox's Minimalist Butt ...

Procreate Drawing Lesson

Procreate painting course resources introduction:...

"Short-term Hot Money Training Course" teaches you how to trade stocks

Course Contents: 01: How to find high-performance...

How to A/B test your app icon

[[145648]] In addition to the app name and previe...

After 40 years of fighting acid rain, Tsinghua University may finally win

China has achieved remarkable results in acid rai...

Baidu Artificial Intelligence

Get the PDF version by scanning the QR code below...