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

Apple will truly achieve password-free login. How will it do it?

At the Worldwide Developers Conference (WWDC) hel...

Galanz sues Tmall for alleged abuse of market dominance

On November 5, 2019, Galanz released an announcem...

Where does astronauts get water outside the earth?

There are three urine collection buckets in front...

Detailed explanation of the new rules for huge amount of Qianchuan investment

I believe everyone is no stranger to the saying &...

iOS 12.3 released to support AirPlay 2-enabled TVs

After six rounds of beta testing, Apple finally r...

How can I make money by posting videos?

The course comes from Jimifeng Technology's s...

How to use Xcode's Targets to manage development and production builds

[[164788]] This post was contributed by Eugene Tr...

Why do early products need seed users?

When it comes to the concept of seed users , I be...

Reusable community operation + live broadcast process!

Due to the impact of the epidemic in 2020, many c...

With all the dividends lost, how to use competitors to increase user growth?

Now many products are facing the dilemma of sever...