當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothGattService.getType方法代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothGattService.getType方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGattService.getType方法的具體用法?Java BluetoothGattService.getType怎麽用?Java BluetoothGattService.getType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.bluetooth.BluetoothGattService的用法示例。


在下文中一共展示了BluetoothGattService.getType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: displayGattServices

import android.bluetooth.BluetoothGattService; //導入方法依賴的package包/類
private void displayGattServices(List<BluetoothGattService> gattServices) {
    if (gattServices == null) return;

    for (BluetoothGattService gattService : gattServices) {
        //-----Service的字段信息-----//
        int type = gattService.getType();
        Log.e(TAG,"-->service type:"+Utils.getServiceType(type));
        Log.e(TAG,"-->includedServices size:"+gattService.getIncludedServices().size());
        Log.e(TAG,"-->service uuid:"+gattService.getUuid());

        //-----Characteristics的字段信息-----//
        List<BluetoothGattCharacteristic> gattCharacteristics =gattService.getCharacteristics();
        for (final BluetoothGattCharacteristic  gattCharacteristic: gattCharacteristics) {
            Log.e(TAG,"---->char uuid:"+gattCharacteristic.getUuid());

            int permission = gattCharacteristic.getPermissions();
            Log.e(TAG,"---->char permission:"+Utils.getCharPermission(permission));

            int property = gattCharacteristic.getProperties();
            Log.e(TAG,"---->char property:"+Utils.getCharPropertie(property));

            byte[] data = gattCharacteristic.getValue();
            if (data != null && data.length > 0) {
                Log.e(TAG,"---->char value:"+new String(data));
            }

            if(gattCharacteristic.getUuid().toString().equals(UUID_RESPONSE)) {
                ResponseCharac = gattCharacteristic;
            }


            //UUID_KEY_DATA是可以跟藍牙模塊串口通信的Characteristic
            if(gattCharacteristic.getUuid().toString().equals(UUID_REQUEST)){
                //測試讀取當前Characteristic數據,會觸發mOnDataAvailable.onCharacteristicRead()
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mBLE.readCharacteristic(gattCharacteristic);
                        mHandler.postDelayed(this, 500);

                        mBLE.readRemoteRssi();

                        //BluetoothGattDescriptor descriptor = gattCharacteristic.getDescriptor(HD_Profile.UUID_CHAR_NOTIFY_DIS)
                    }
                }, 500);

                //接受Characteristic被寫的通知,收到藍牙模塊的數據後會觸發mOnDataAvailable.onCharacteristicWrite()
                mBLE.setCharacteristicNotification(gattCharacteristic, true);

                //設置數據內容
                //gattCharacteristic.setValue("hi");
                //往藍牙模塊寫入數據
              // mBLE.writeCharacteristic(gattCharacteristic);
            }




            //-----Descriptors的字段信息-----//
            List<BluetoothGattDescriptor> gattDescriptors = gattCharacteristic.getDescriptors();
            for (BluetoothGattDescriptor gattDescriptor : gattDescriptors) {
                Log.e(TAG, "-------->desc uuid:" + gattDescriptor.getUuid());
                int descPermission = gattDescriptor.getPermissions();
                Log.e(TAG,"-------->desc permission:"+ Utils.getDescPermission(descPermission));

                byte[] desData = gattDescriptor.getValue();
                if (desData != null && desData.length > 0) {
                    Log.e(TAG, "-------->desc value:"+ new String(desData));
                }
            }
        }
    }//

}
 
開發者ID:haoyifan,項目名稱:BLE-PEPS,代碼行數:75,代碼來源:BleClientMainActivity.java


注:本文中的android.bluetooth.BluetoothGattService.getType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。