日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Android源碼下載:Bluetooth_4.3BLE藍(lán)牙通信

功能分類:工具

支持平臺:Android

運行環(huán)境:Eclipse

開發(fā)語言:Java

開發(fā)工具:Eclipse

源碼大?。?.37MB

源碼簡介

該Demo主要是兼容了支持BLE的Android4.3終端設(shè)備之間的藍(lán)牙通信。

主要功能包含:

1、藍(lán)牙的開啟、關(guān)閉;

2、周圍藍(lán)牙開啟設(shè)備的搜索、建連

3、成功建連后,通過藍(lán)牙向?qū)Ψ桨l(fā)送消息。

注:要想觀察發(fā)送/接收消息,必須雙方都安裝了此APP。

源碼運行截圖

APP打開藍(lán)牙時,對藍(lán)牙的請求

藍(lán)牙通信

搜索周圍安裝該APP的藍(lán)牙設(shè)備

設(shè)置藍(lán)牙的某些屬性值

源碼片段

 
 
 
 
  1. private void scanLeDevice(final boolean enable) { 

            if (enable) {

  2.             // Stops scanning after a pre-defined scan period. 

                mHandler.postDelayed(new Runnable() {

  3.                 @Override 

                    public void run() {

  4.                     mScanning = false; 

                        mBluetoothAdapter.stopLeScan(mLeScanCallback);

  5.                     invalidateOptionsMenu(); 

                    }

  6.             }, SCAN_PERIOD);
  7.             mScanning = true; 

                mBluetoothAdapter.startLeScan(mLeScanCallback);

  8.         } else { 

                mScanning = false;

  9.             mBluetoothAdapter.stopLeScan(mLeScanCallback); 

            }

  10.         invalidateOptionsMenu(); 

        }

  11.   

        // Adapter for holding devices found through scanning.

  12.     private class LeDeviceListAdapter extends BaseAdapter { 

            private ArrayList mLeDevices;

  13.         private LayoutInflater mInflator;
  14.         public LeDeviceListAdapter() { 

                super();

  15.             mLeDevices = new ArrayList(); 

                mInflator = DeviceScanActivity.this.getLayoutInflater();

  16.         }
  17.         public void addDevice(BluetoothDevice device) { 

                if(!mLeDevices.contains(device)) {

  18.                 mLeDevices.add(device); 

                }

  19.         }
  20.         public BluetoothDevice getDevice(int position) { 

                return mLeDevices.get(position);

  21.         }
  22.         public void clear() { 

                mLeDevices.clear();

  23.         }
  24.         @Override 

            public int getCount() {

  25.             return mLeDevices.size(); 

            }

  26.   

            @Override

  27.         public Object getItem(int i) { 

                return mLeDevices.get(i);

  28.         }
  29.         @Override 

            public long getItemId(int i) {

  30.             return i; 

            }

  31.   

            @Override

  32.         public View getView(int i, View view, ViewGroup viewGroup) { 

                ViewHolder viewHolder;

  33.             // General ListView optimization code. 

                if (view == null) {

  34.                 view = mInflator.inflate(R.layout.listitem_device, null); 

                    viewHolder = new ViewHolder();

  35.                 viewHolder.deviceAddress = (TextView) view.findViewById(R.id.device_address); 

                    viewHolder.deviceName = (TextView) view.findViewById(R.id.device_name);

  36.                 view.setTag(viewHolder); 

                } else {

  37.                 viewHolder = (ViewHolder) view.getTag(); 

                }

  38.   

                BluetoothDevice device = mLeDevices.get(i);

  39.             final String deviceName = device.getName(); 

                if (deviceName != null && deviceName.length() > 0)

  40.                 viewHolder.deviceName.setText(deviceName); 

                else

  41.                 viewHolder.deviceName.setText(R.string.unknown_device); 

                viewHolder.deviceAddress.setText(device.getAddress());

  42.   

                return view;

  43.         } 

        }

  44.   

        // Device scan callback.

  45.     private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
  46.         @Override 

            public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {

  47.             runOnUiThread(new Runnable() { 

                    @Override

  48.                 public void run() { 

                        mLeDeviceListAdapter.addDevice(device);

  49.                     mLeDeviceListAdapter.notifyDataSetChanged(); 

                    }

  50.             }); 

            }

  51.     }; 


本文標(biāo)題:Android源碼下載:Bluetooth_4.3BLE藍(lán)牙通信
當(dāng)前網(wǎng)址:http://m.5511xx.com/article/dpejehi.html