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

Evaluation of the effectiveness of Xiaohongshu advertising!

What do you think about whether Xiaohongshu adver...

How to attract new users through APP user operations?

How will we leverage the momentum, coordinate res...

Spiders play mahjong? This little spider throws a four-piece card at you!

What is March 14th? White Day? Pi Day? Not only t...

How to build your first machine learning model on your iPhone

introduction As a data scientist, I have always h...

Tesla's sales are slowing down? No, this is just the beginning!

How long has it been since Tesla launched a new m...

Do product managers need to learn technology? Here is the best answer

I have always believed that learning new knowledg...

How can we make the marketing information of a product spread widely?

As an Internet product person, you will more or l...

Dating and marriage: mathematics can help you find the best partner

Lovers will eventually marry. When we choose blin...