三星gs3:android ble 蓝牙4.0开发日志(一)

 

此次android开发针对三星gs3开发,特以此文给正在开发ble4.0的童鞋们一点启示。

我们要开发基于android ble4.0的app,那么我们首先需要一个开发包,也就是一个android.jar或者是ble.jar,这其中包含了我们进行ble开发的一些类,下面我贴上这些类,我贴上一些类的代码,给大家参考下,不再是某些人的类介绍而已。

由于这些类都是通过反编译的,可能有错,这些类是不需要加入到源码中的,大家可以进群(群号见最后)下载ble_sunsang.jar,注意这里肯定有童鞋说我加入了,eclipse给我编死了,这是因为你把这个jar放到了工程里了,这里要以外部包的方式引入喔,切记。

开始介绍相关类:BluetoothLEClientChar.java

此类是用于接收发送数据的 封装类,也就是说蓝牙通过uuid发送和接收都是通过此类来完成。

package com.samsung.bluetoothle;import android.os.Parcel;import android.os.Parcelable;import android.os.Parcelable.Creator;import android.util.Log;public class BluetoothLEClientChar implements Parcelable{ public static final Parcelable.Creator<BluetoothLEClientChar> CREATOR = new Parcelable.Creator() { public BluetoothLEClientChar createFromParcel(Parcel paramParcel) { return new BluetoothLEClientChar(paramParcel.readString()); } public BluetoothLEClientChar[] newArray(int paramInt) { return new BluetoothLEClientChar[paramInt]; } }; private static final boolean DEBUG = true; private static final String TAG = "BluetoothLEClientChar"; private String mCharPath; private String mCharUUID; private byte[] mClientDesc; private String mDescription; private String mName; private byte[] mValue; public BluetoothLEClientChar(String paramString) { this.mCharPath = paramString; } private void LogD(String paramString) { Log.d("BluetoothLEClientChar", paramString); } public int describeContents() { return 0; } public String getCharPath() { LogD("getCharPath:" + this.mCharPath); return this.mCharPath; } public String getCharUUID() { LogD("getCharUUID:" + this.mCharUUID); return this.mCharUUID; } public byte[] getCharVaule() { LogD("getCharVaule "); byte[] arrayOfByte; if (this.mValue != null) { int i = this.mValue.length; arrayOfByte = new byte[i]; System.arraycopy(this.mValue, 0, arrayOfByte, 0, i); } while (true) { return arrayOfByte; LogD("the value is not initialized"); arrayOfByte = null; } } public byte[] getClientConfigDesc() { LogD("getClientConfigDesc : "); byte[] arrayOfByte; if (this.mClientDesc != null) { int i = this.mClientDesc.length; arrayOfByte = new byte[i]; System.arraycopy(this.mClientDesc, 0, arrayOfByte, 0, i); } while (true) { return arrayOfByte; LogD("the value is not initialized"); arrayOfByte = null; } } void setCharPath(String paramString) { LogD("setCharPath:" + paramString); this.mCharPath = paramString; } public void setCharValue(byte[] paramArrayOfByte) { LogD("setCharValue of char : " + this.mCharPath); int i = paramArrayOfByte.length; this.mValue = null; this.mValue = new byte[i]; System.arraycopy(paramArrayOfByte, 0, this.mValue, 0, i); } public void setClientConfigDesc(byte[] paramArrayOfByte) { LogD("setClientConfigDes of char : " + this.mCharPath); int i = paramArrayOfByte.length; this.mClientDesc = null; this.mClientDesc = new byte[i]; System.arraycopy(paramArrayOfByte, 0, this.mClientDesc, 0, i); } void setProperty(String paramString1, String paramString2) { LogD("setProperty name : " + paramString1 + " : Value :" + paramString2); if (paramString1.equals("Value")) { if ((paramString2 == null) || (paramString2.length() == 0)) { this.mValue = new byte[1]; this.mValue[0] = 0; } while (true) { for (int j = 0; j < this.mValue.length; j++) LogD("setProperty Value :" + (char)this.mValue[j]); LogD("Check size of string " + paramString2.length()); try { this.mValue = paramString2.getBytes("UTF8"); } catch (Exception localException2) { Log.e("BluetoothLEClientChar", "## Exception in conversion"); } } } if (paramString1.equals("Name")) this.mName = paramString2; while (true) { return; if (paramString1.equals("UUID")) { this.mCharUUID = paramString2; continue; } if (paramString1.equals("ClientDescriptor")) { if ((paramString2 == null) || (paramString2.length() == 0)) { this.mClientDesc = new byte[1]; this.mClientDesc[0] = 0; } while (true) { for (int i = 0; i < this.mClientDesc.length; i++) LogD("setProperty mClientDesc :" + (char)this.mClientDesc[i]); break; Log.e("BluetoothLEClientChar", "Check size of string " + paramString2.length()); try { this.mClientDesc = paramString2.getBytes("UTF8"); } catch (Exception localException1) { Log.e("BluetoothLEClientChar", "## Exception in conversion"); } } } if (!paramString1.equals("Description")) continue; this.mDescription = paramString2; } } public void setcharUUID(String paramString) { this.mCharUUID = paramString; } public void writeToParcel(Parcel paramParcel, int paramInt) { }}

BluetoothLEClientProfile类用来管理和LE设备的连接 也就是断开,连接,掉线,refresh 等… 我们要和le来连接我们必须重新写一个子类然后 继承于BluetoothLEClientProfile。

package com.samsung.bluetoothle;import android.bluetooth.BluetoothDevice;import android.content.Context;import android.os.Handler;import android.os.Message;import android.util.Log;import java.util.ArrayList;public abstract class BluetoothLEClientProfile{ private static final boolean DEBUG = true; public static final int GATT_STATE_CONNECTED = 2; public static final int GATT_STATE_CONNECTING = 1; public static final int GATT_STATE_DISCONNECTED = 0; public static final int GATT_STATE_DISCONNECTING = 3; private static final String TAG = "BluetoothLEClientProfile"; private static int mState; private BluetoothLEClientCallback mCallback; private Context mContext; private BluetoothDevice mDevice; private BluetoothLEGattProxy mGattProxy; private final Handler mHandler = new Handler() { public void handleMessage(Message paramMessage) { switch (paramMessage.what) { case 2: default: case 1: case 3: } while (true) { return; String str2 = (String)paramMessage.obj; if (str2 == null) continue; BluetoothLEClientProfile.this.mCallback.onConnected(str2); continue; String str1 = (String)paramMessage.obj; if (str1 == null) continue; BluetoothLEClientProfile.this.mCallback.onDisconnected(str1); } } }; private ArrayList mRequiredServices; public BluetoothLEClientProfile(Context paramContext) { LogD("BluetoothLEClientProfile", "BluetoothLEClientProfile"); this.mContext = paramContext; this.mCallback = new BluetoothLEClientCallback(); this.mGattProxy = BluetoothLEGattProxy.getProxy(); mState = 0; } private void LogD(String paramString1, String paramString2) { Log.d(paramString1, paramString2); } public boolean connectLEDevice(BluetoothDevice paramBluetoothDevice) { int i = 1; LogD("BluetoothLEClientProfile", "connectLEDevice"); this.mDevice = paramBluetoothDevice; mState = i; LogD("BluetoothLEClientProfile", "LE device connection state :" + paramBluetoothDevice.isLEDeviceConnected()); if (paramBluetoothDevice.isLEDeviceConnected()) { LogD("BluetoothLEClientProfile", "LE device connection state :" + paramBluetoothDevice.isLEDeviceConnected()); Message localMessage = this.mHandler.obtainMessage(i); localMessage.obj = paramBluetoothDevice.getAddress(); this.mHandler.sendMessage(localMessage); } while (true) { return i; boolean bool = this.mGattProxy.connect(paramBluetoothDevice); } } public boolean disconnectLEDevice(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientProfile", "disconnectLEDevice"); mState = 3; LogD("BluetoothLEClientProfile", "LE device connection state :" + paramBluetoothDevice.isLEDeviceConnected()); if (!paramBluetoothDevice.isLEDeviceConnected()) { LogD("BluetoothLEClientProfile", "LE device connection state :" + paramBluetoothDevice.isLEDeviceConnected()); Message localMessage = this.mHandler.obtainMessage(3); localMessage.obj = paramBluetoothDevice.getAddress(); this.mHandler.sendMessage(localMessage); } for (boolean bool = true; ; bool = this.mGattProxy.disconnect(paramBluetoothDevice)) return bool; } public void discoverCharacteristics(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientProfile", "discoverCharacteristics"); if (mState == 2) for (int i = 0; i < this.mRequiredServices.size(); i++) ((BluetoothLEClientService)this.mRequiredServices.get(i)).discoverCharacteristics(paramBluetoothDevice); } public void finish() { LogD("BluetoothLEClientProfile", "finish"); mState = 0; this.mRequiredServices.clear(); this.mRequiredServices = null; this.mGattProxy = null; this.mCallback = null; } public BluetoothDevice getConnectedLEDevice() { return this.mDevice; } BluetoothLEGattProxy getGattProxy() { return this.mGattProxy; } public int getLEProfileState() { LogD("BluetoothLEClientProfile", "getLEProfileState: " + mState); return mState; } public void getRssiValue(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientProfile", "disconnectLEDevice"); this.mGattProxy.getRssiValue(paramBluetoothDevice); } public void onDiscoverCharacteristics(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientProfile", "onDiscoverCharacteristics"); } public void onGetRssiValue(BluetoothDevice paramBluetoothDevice, String paramString) { LogD("BluetoothLEClientProfile", "onGetRssiValue"); } public void onLEDeviceConnected(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientProfile", "onLEDeviceConnected"); } public void onLEDeviceDisconnected(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientProfile", "onLEDeviceDisconnected"); } public void onLELinkLoss(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientProfile", "onLELinkLoss"); } public void registerLEProfile(ArrayList paramArrayList) { LogD("BluetoothLEClientProfile", "registerLEProfile"); this.mRequiredServices = paramArrayList; this.mGattProxy.registerLEProfile(this.mCallback); } public void setRemoteDevice(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientProfile", "setRemoteDevice"); this.mDevice = paramBluetoothDevice; this.mGattProxy.setRemoteDeviceAddress(paramBluetoothDevice); } public void unregisterLEProfile() { LogD("BluetoothLEClientProfile", "unregisterLEProfile"); if ((mState == 1) || (mState == 2)) disconnectLEDevice(this.mDevice); this.mGattProxy.unregisterLEProfile(); } void updateRefreshState(String paramString) { LogD("BluetoothLEClientProfile", "updateRefreshState"); int i = this.mRequiredServices.size(); if (((BluetoothLEClientService)this.mRequiredServices.get(i - 1)).getServicePath().equals(paramString)) onDiscoverCharacteristics(this.mDevice); } private class BluetoothLEClientCallback extends IBluetoothLEClientCallBack.Stub { private static final String TAG = "BluetoothLEClientCallback"; BluetoothLEClientCallback() { } public void onConnected(String paramString) { BluetoothLEClientProfile.this.LogD("BluetoothLEClientCallback", "----- onConnected"); BluetoothLEClientProfile.access$202(2); for (int i = 0; i < BluetoothLEClientProfile.this.mRequiredServices.size(); i++) ((BluetoothLEClientService)BluetoothLEClientProfile.this.mRequiredServices.get(i)).init(BluetoothLEClientProfile.this.mDevice, BluetoothLEClientProfile.this); BluetoothLEClientProfile.this.onLEDeviceConnected(BluetoothLEClientProfile.this.mDevice); } public void onDisconnected(String paramString) { BluetoothLEClientProfile.this.LogD("BluetoothLEClientCallback", "----- onDisconnected"); BluetoothLEClientProfile.access$202(0); for (int i = 0; i < BluetoothLEClientProfile.this.mRequiredServices.size(); i++) { if (!((BluetoothLEClientService)BluetoothLEClientProfile.this.mRequiredServices.get(i)).isCharDiscoveryInProgress()) continue; ((BluetoothLEClientService)BluetoothLEClientProfile.this.mRequiredServices.get(i)).setCharDiscoveryProgress(false); } BluetoothLEClientProfile.this.onLEDeviceDisconnected(BluetoothLEClientProfile.this.mDevice); } public void onGetRssiValue(String paramString) { BluetoothLEClientProfile.this.LogD("BluetoothLEClientCallback", "onGetRssiValue"); BluetoothLEClientProfile.this.onGetRssiValue(BluetoothLEClientProfile.this.mDevice, paramString); } public void onLinkLoss() { BluetoothLEClientProfile.this.LogD("BluetoothLEClientCallback", "onLinkLoss"); BluetoothLEClientProfile.this.onLELinkLoss(BluetoothLEClientProfile.this.mDevice); } }}

BluetoothLEClientService.java 顾名思义 此是le设备通信服务类,这个类主要用于监听UUID,UUID你可以理解为是一个特殊的端口,特殊的通信道路,只有LE设备和手机两侧 UUID一致然后才能进行通信,这个服务就是用来管理通信的。  也需要自己重新写子类然后继承于BluetoothLEService.java

package com.samsung.bluetoothle;import android.bluetooth.BluetoothDevice;import android.util.Log;import java.util.ArrayList;public abstract class BluetoothLEClientService{ private static final boolean DEBUG = true; public static final int GATT_WRITE_CMD = 0; public static final int GATT_WRITE_REQ = 1; private static final String TAG = "BluetoothLEClientService"; private boolean discoverCharInProgress = false; private boolean isDiscoverCharByUUID = false; private BluetoothLEClientCharUpdationCallBack mCallback; private BluetoothLEClientProfile mProfile; private ArrayList<BluetoothLEClientChar> mServiceChars; private String mServicePath = null; private String mServiceUUID; public BluetoothLEClientService(String paramString) { LogD("BluetoothLEClientService", "BluetoothLEClientService"); this.mServiceUUID = paramString; this.mCallback = new BluetoothLEClientCharUpdationCallBack(); this.mProfile = null; this.mServiceChars = new ArrayList(); } private void LogD(String paramString1, String paramString2) { Log.d(paramString1, paramString2); } private BluetoothLEClientChar getCharbyPath(String paramString) { LogD("BluetoothLEClientService", "getCharbyPath"); int i = 0; BluetoothLEClientChar localBluetoothLEClientChar; if (i < this.mServiceChars.size()) { localBluetoothLEClientChar = (BluetoothLEClientChar)this.mServiceChars.get(i); if (!localBluetoothLEClientChar.getCharPath().equals(paramString)); } while (true) { return localBluetoothLEClientChar; i++; break; localBluetoothLEClientChar = null; } } private void updateServiceChars(String paramString, String[] paramArrayOfString) { LogD("BluetoothLEClientService", "updateServiceChars"); if (this.mProfile.getLEProfileState() == 2) { this.mServiceChars.clear(); for (int i = 0; i < paramArrayOfString.length; i++) { LogD("BluetoothLEClientService", "Charpath :" + paramArrayOfString[i]); String[] arrayOfString = this.mProfile.getGattProxy().gattGetCharProperties(paramString, paramArrayOfString[i]); BluetoothLEClientChar localBluetoothLEClientChar = new BluetoothLEClientChar(paramArrayOfString[i]); if (arrayOfString == null) continue; for (int j = 0; j < arrayOfString.length; j += 2) localBluetoothLEClientChar.setProperty(arrayOfString[j], arrayOfString[(j + 1)]); this.mServiceChars.add(localBluetoothLEClientChar); } this.mProfile.updateRefreshState(this.mServicePath); } } private void updateSingleChar(String paramString1, String paramString2) { LogD("BluetoothLEClientService", "updateSingleChar"); if (this.mProfile.getLEProfileState() == 2) { BluetoothLEClientChar localBluetoothLEClientChar = getCharbyPath(paramString2); int i = 0; if (localBluetoothLEClientChar == null) { localBluetoothLEClientChar = new BluetoothLEClientChar(paramString2); i = 1; } String[] arrayOfString = this.mProfile.getGattProxy().gattGetCharProperties(paramString1, paramString2); if (arrayOfString != null) { for (int j = 0; j < arrayOfString.length; j += 2) localBluetoothLEClientChar.setProperty(arrayOfString[j], arrayOfString[(j + 1)]); if (i != 0) this.mServiceChars.add(localBluetoothLEClientChar); onDiscoverCharacteristics(localBluetoothLEClientChar); } } } private void waitDiscoveryDone() { monitorenter; try { LogD("BluetoothLEClientService", "waitDiscoveryDone"); try { wait(70000L); monitorexit; return; } catch (InterruptedException localInterruptedException) { while (true) Log.e("BluetoothLEClientService", "Characteristics discovery takes too long"); } } finally { monitorexit; } throw localObject; } public void discoverCharacteristics(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientService", "discoverCharacteristics"); if (this.mServicePath != null) { if (this.discoverCharInProgress) waitDiscoveryDone(); setCharDiscoveryProgress(true); this.mProfile.getGattProxy().gattDiscoveryCharacteristics(paramBluetoothDevice.getAddress(), this.mServicePath, "0xffff"); } } public void discoverCharacteristics(BluetoothDevice paramBluetoothDevice, String paramString) { LogD("BluetoothLEClientService", "discoverCharacteristics :" + paramString); if (this.mServicePath != null) { if (this.discoverCharInProgress) waitDiscoveryDone(); setCharDiscoveryProgress(true); this.isDiscoverCharByUUID = true; this.mProfile.getGattProxy().gattDiscoveryCharacteristics(paramBluetoothDevice.getAddress(), this.mServicePath, paramString); } } public ArrayList getAllChars(BluetoothDevice paramBluetoothDevice) { LogD("BluetoothLEClientService", "getAllChars"); if (paramBluetoothDevice.equals(this.mProfile.getConnectedLEDevice())); for (ArrayList localArrayList = this.mServiceChars; ; localArrayList = null) return localArrayList; } public BluetoothLEClientChar getCharbyUUID(BluetoothDevice paramBluetoothDevice, String paramString) { LogD("BluetoothLEClientService", "getChar"); int i; BluetoothLEClientChar localBluetoothLEClientChar; if (paramBluetoothDevice.equals(this.mProfile.getConnectedLEDevice())) { i = 0; if (i < this.mServiceChars.size()) { localBluetoothLEClientChar = (BluetoothLEClientChar)this.mServiceChars.get(i); if (!localBluetoothLEClientChar.getCharUUID().equals(paramString)); } } while (true) { return localBluetoothLEClientChar; i++; break; localBluetoothLEClientChar = null; } } String getServicePath() { return this.mServicePath; } void init(BluetoothDevice paramBluetoothDevice, BluetoothLEClientProfile paramBluetoothLEClientProfile) { LogD("BluetoothLEClientService", "init"); String[] arrayOfString = paramBluetoothDevice.getRemoteServicePaths(); this.mProfile = paramBluetoothLEClientProfile; for (int i = 0; ; i++) { if (i < arrayOfString.length) { String str = paramBluetoothDevice.getRemoteServiceUUID(arrayOfString[i]); if (str.length() == 4) str = "0000" + str + "-0000-1000-8000-00805f9b34fb"; if (!this.mServiceUUID.equals(str)) continue; this.mServicePath = arrayOfString[i]; registerLEServiceCallback(); } return; } } boolean isCharDiscoveryInProgress() { return this.discoverCharInProgress; } public void onDiscoverCharacteristics(BluetoothLEClientChar paramBluetoothLEClientChar) { LogD("BluetoothLEClientService", "onDiscoverCharacteristics"); } public void onWatcherValueChanged(BluetoothLEClientChar paramBluetoothLEClientChar) { LogD("BluetoothLEClientService", "onWatcherValueChanged"); } public void onWriteCharValue(BluetoothLEClientChar paramBluetoothLEClientChar, String paramString) { LogD("BluetoothLEClientService", "onWriteCharValue"); } public void onWriteClientConfigDesc(BluetoothLEClientChar paramBluetoothLEClientChar, String paramString) { LogD("BluetoothLEClientService", "onWriteClientConfigDesc"); } public int readCharValue(BluetoothDevice paramBluetoothDevice, String paramString) { LogD("BluetoothLEClientService", "readCharValue"); return 0; } public void registerLEServiceCallback() { LogD("BluetoothLEClientService", "registerLEServiceCallback"); this.mProfile.getGattProxy().registerLEServiceCallback(this.mServicePath, this.mCallback); } public boolean registerWatcher() { LogD("BluetoothLEClientService", "registerWatcher"); return this.mProfile.getGattProxy().registerWatcher(this.mServicePath); } void setCharDiscoveryProgress(boolean paramBoolean) { LogD("BluetoothLEClientService", "setDiscoveryProgress::" + paramBoolean); this.discoverCharInProgress = paramBoolean; } public boolean unregisterWatcher() { LogD("BluetoothLEClientService", "unregisterWatcher"); return this.mProfile.getGattProxy().unregisterWatcher(this.mServicePath); } public int writeCharValue(BluetoothLEClientChar paramBluetoothLEClientChar, int paramInt) { LogD("BluetoothLEClientService", "writeCharValue"); String str1 = this.mProfile.getConnectedLEDevice().getAddress(); String str2 = paramBluetoothLEClientChar.getCharPath(); byte[] arrayOfByte = paramBluetoothLEClientChar.getCharVaule(); String str3; if (paramInt == 1) str3 = "WRITE_REQ"; while (true) { if ((str1 != null) && (str2 != null) && (arrayOfByte != null)) this.mProfile.getGattProxy().gattSetCharProperty(str1, str3, str2, "Value", arrayOfByte); return 0; str3 = null; if (paramInt != 0) continue; str3 = "WRITE_CMD"; } } public int writeClientConfigDesc(BluetoothLEClientChar paramBluetoothLEClientChar) { LogD("BluetoothLEClientService", "writeClientConfigDesc"); String str1 = this.mProfile.getConnectedLEDevice().getAddress(); String str2 = paramBluetoothLEClientChar.getCharPath(); byte[] arrayOfByte = paramBluetoothLEClientChar.getClientConfigDesc(); if ((str1 != null) && (str2 != null) && (arrayOfByte != null)) this.mProfile.getGattProxy().gattSetCharProperty(str1, "WRITE_REQ", str2, "ClientConfiguration", arrayOfByte); return 0; } private class BluetoothLEClientCharUpdationCallBack extends IBluetoothLEClientCharUpdationCallBack.Stub { private static final String TAG = "BluetoothLEClientCharUpdationCallBack"; BluetoothLEClientCharUpdationCallBack() { } public void onDiscoverCharacteristics(String paramString, String[] paramArrayOfString) { BluetoothLEClientService.this.LogD("BluetoothLEClientCharUpdationCallBack", "onDiscoverCharacteristics length : " + paramArrayOfString.length); if (BluetoothLEClientService.this.isDiscoverCharByUUID) { BluetoothLEClientService.this.updateSingleChar(paramString, paramArrayOfString[0]); BluetoothLEClientService.access$202(BluetoothLEClientService.this, false); } while (true) { BluetoothLEClientService.this.setCharDiscoveryProgress(false); try { notify(); label71: return; BluetoothLEClientService.this.updateServiceChars(paramString, paramArrayOfString); } catch (IllegalMonitorStateException localIllegalMonitorStateException) { break label71; } } } public void onReadCharValue(String paramString) { BluetoothLEClientService.this.LogD("BluetoothLEClientCharUpdationCallBack", "onReadCharValue"); } public void onWatcherValueChanged(String paramString1, String paramString2) { BluetoothLEClientService.this.LogD("BluetoothLEClientCharUpdationCallBack", "onWatcherValueChanged char Path :" + paramString1 + " value :" + paramString2); for (int i = 0; ; i++) { if (i < BluetoothLEClientService.this.mServiceChars.size()) { if (!paramString1.equals(((BluetoothLEClientChar)BluetoothLEClientService.this.mServiceChars.get(i)).getCharPath())) continue; BluetoothLEClientChar localBluetoothLEClientChar = (BluetoothLEClientChar)BluetoothLEClientService.this.mServiceChars.get(i); localBluetoothLEClientChar.setProperty("Value", paramString2); BluetoothLEClientService.this.onWatcherValueChanged(localBluetoothLEClientChar); } return; } } public void onWriteCharValue(String paramString1, String paramString2) { BluetoothLEClientService.this.LogD("BluetoothLEClientCharUpdationCallBack", "onWriteCharValue char Path :" + paramString1 + " status :" + paramString2); BluetoothLEClientChar localBluetoothLEClientChar = null; for (int i = 0; ; i++) { if (i < BluetoothLEClientService.this.mServiceChars.size()) { localBluetoothLEClientChar = (BluetoothLEClientChar)BluetoothLEClientService.this.mServiceChars.get(i); if (!paramString1.equals(localBluetoothLEClientChar.getCharPath())) continue; } BluetoothLEClientService.this.onWriteCharValue(localBluetoothLEClientChar, paramString2); return; } } public void onWriteClientConfigDesc(String paramString1, String paramString2) { BluetoothLEClientService.this.LogD("BluetoothLEClientCharUpdationCallBack", "onWriteClientConfigDesc char Path :" + paramString1 + " status :" + paramString2); BluetoothLEClientChar localBluetoothLEClientChar = null; for (int i = 0; ; i++) { if (i < BluetoothLEClientService.this.mServiceChars.size()) { localBluetoothLEClientChar = (BluetoothLEClientChar)BluetoothLEClientService.this.mServiceChars.get(i); if (!paramString1.equals(localBluetoothLEClientChar.getCharPath())) continue; } BluetoothLEClientService.this.onWriteClientConfigDesc(localBluetoothLEClientChar, paramString2); return; } } }}

BluetoothLENamespace.java类就是一系列 UUID 通过BluetoothLENamespace.toUuid128StringFormat(BluetoothLENamespace.BatteryService)这样就能得到电池服务的UUID了。

package com.samsung.bluetoothle;public final class BluetoothLENamespace{ public static String toUuid128StringFormat(int paramInt) { StringBuilder localStringBuilder = new StringBuilder("0000"); localStringBuilder.append(Integer.toHexString(paramInt)); localStringBuilder.append("-0000-1000-8000-00805f9b34fb"); return localStringBuilder.toString(); } public static String toUuid16StringFormat(int paramInt) { return Integer.toHexString(paramInt); } public static final class Characteristics { public static final int AlertLevel = 10758; public static final int BodySensorLocation = 10808; public static final int FirmwareRevision = 10790; public static final int HardwareRevision = 10791; public static final int HeartRateControlPoint = 10809; public static final int HeartRateMeasurement = 10807; public static final int IEEE_11073_20601_RegulatoryCertificationDataList = 10794; public static final int ManufactureName = 10793; public static final int ModelNumber = 10788; public static final int SerialNumber = 10789; public static final int SoftwareRevision = 10792; public static final int SystemId = 10787; public static final int TxPowerLevel = 10759; } public static final class Services { public static final int AlertNotificationService = 6161; public static final int BatteryService = 6159; public static final int BloodPressure = 6160; public static final int CurrentTimeService = 6149; public static final int DeviceInformationService = 6154; public static final int GenericAccess = 6144; public static final int GenericAttribute = 6145; public static final int HealthThermometer = 6153; public static final int HeartRate = 6157; public static final int HumanInterfaceDevice = 6162; public static final int ImmediateAlert = 6146; public static final int LinkLoss = 6147; public static final int NextDSTChangeService = 6151; public static final int PhoneAlertStatusService = 6158; public static final int ReferenceTimeUpdateService = 6150; public static final int ScanParameters = 6163; public static final int TxPower = 6148; }}

 

好了,此文暂时写到这里,待后续更新。。

ble 4.0交流QQ群:293885474  加群备注:android ble开发者

转载于:https://www.cnblogs.com/luwenbin/archive/2013/04/27/3046625.html

相关推荐

相关文章