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

Double 11’s 268.4 billion, the most authentic marketing insights

It is no exaggeration to say that Tmall Double 11...

A large wave of August marketing hotspots is coming!

July has passed quietly, and it’s time to start p...

Why do I keep going to the toilet after drinking milk tea or coffee? ? ?

Planning and production Source: Curious Doctor Ed...

From tactics to strategy, 7 ways to get early seed users for App promotion

All startups will face the problem of how to acqu...

Knowledge sharing will be the new direction for the future explosion of robots

What if robots could solve more problems independ...

International first! Chinese scientists have made a major breakthrough

Quantum simulation experiments have made a major ...

The Milky Way has a mysterious sister? It can be seen with the naked eye!

Author | Feng Ziyang Review | Dong Chenhui Editor...

Take you into the secrets behind the red envelopes in Moments photos!

The WeChat Moments photo red envelopes were in fu...

A ready-to-use product analysis framework

This is an original article about product analysi...

In this lonely universe, are humans an exception?

In this lonely universe, are humans an exception?...