本文整理匯總了Java中android.bluetooth.BluetoothGatt.discoverServices方法的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothGatt.discoverServices方法的具體用法?Java BluetoothGatt.discoverServices怎麽用?Java BluetoothGatt.discoverServices使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.bluetooth.BluetoothGatt
的用法示例。
在下文中一共展示了BluetoothGatt.discoverServices方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onMtuChanged
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
super.onMtuChanged(gatt, mtu, status);
if ( status == BluetoothGatt.GATT_SUCCESS )
{
NLog.d("call onMtuChanged");
gatt.discoverServices();
}
else
{
// 적용가능한 최대 크기의 MTU찾기
NLog.d("call onMtuChanged status : " + status + ", mtu : " + mtu);
if ( mtuIndex >= mtuLIst.length )
{
NLog.d("error request mtu failed");
}
BTLEAdt.this.mtu = BTLEAdt.this.mtuLIst[++mtuIndex];
gatt.requestMtu(BTLEAdt.this.mtu);
}
}
示例2: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
if (newState == BluetoothProfile.STATE_CONNECTED) {
connected = true;
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
connected = false;
btGatt.close();
btGatt = null;
charSerial = null;
messenger.obtainMessage(MessageConstants.STATUS, StatusCode.Disconnected).sendToTarget();
} else {
messenger.obtainMessage(MessageConstants.ERROR, ErrorCode.Connect).sendToTarget();
taskConnectTimeout.cancel();
}
}
示例3: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
* Callback indicating when GATT client has connected/disconnected to/from a remote
* GATT server.
*
* @param gatt GATT client
* @param status Status of the connect or disconnect operation.
* {@link BluetoothGatt#GATT_SUCCESS} if the operation succeeds.
* @param newState Returns the new connection state. Can be one of
* {@link android.bluetooth.BluetoothProfile#STATE_DISCONNECTED} or
* {@link android.bluetooth.BluetoothProfile#STATE_CONNECTED}
*/
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
// boolean indicating whether or not the next step is successful, default is false
boolean success = false;
// Start Service discovery if we're now connected
if (status == BluetoothGatt.GATT_SUCCESS) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
success = gatt.discoverServices();
} // else: not connected, continue
} // else: not successful
onStep(gatt, success);
}
示例4: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState)
{
switch(newState)
{
case BluetoothProfile.STATE_CONNECTED:
Log.d(TAG, "Gatt state: connected");
gatt.discoverServices();
isConnectedToGatt = true;
raiseonConnect();
break;
default:
Log.d(TAG, "Gatt state: not connected");
isConnectedToGatt = false;
raiseonDisconnect();
break;
}
}
示例5: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.d(TAG, "BluetoothGattCallback.nConnectionStateChange: status=" + status + " newState=" + newState);
updateLog("Bluetooth connection state change: status="+ status + " newState=" + newState);
if (newState == BluetoothProfile.STATE_CONNECTED) {
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
if (gatt.getDevice().getAddress().equals(mOWDevice.deviceMacAddress.get())) {
onOWStateChangedToDisconnected(gatt);
}
updateLog("--> Closed " + gatt.getDevice().getAddress());
Log.d(TAG, "Disconnect:" + gatt.getDevice().getAddress());
}
}
示例6: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
LogUtils.d(TAG, "onConnctionStateChange:" + Thread.currentThread().toString());
if (BluetoothProfile.STATE_CONNECTED == newState) {
//連接成功
LogUtils.i(TAG, "onConnectionStateChange():連接成功,得到gatt,status = " + status);
mState = State.STATE_CONNECTED;
//發現服務
boolean b = gatt.discoverServices();
LogUtils.d(TAG, "試圖查詢 gatt 上的 services :" + b);
//發送消息給 Activity
sendMsgToClient(MsgClient.MSG_GATT_CONNECTED, null);
} else if (BluetoothProfile.STATE_DISCONNECTED == newState) {
//返回連接斷開的消息
sendMsgToClient(MsgClient.MSG_CONNECTED_DISMISS, null);
//取消周期行讀取 rssi 的操作
cancelAllTasks();
//清除當前 gatt
refreshDeviceCache();
gatt.disconnect();//不使用自帶的重連功能
closeGatt();
//定時重連操作
mScheduledThreadPool.schedule(task1, Attributes.RE_CONNECTING_TIME, TimeUnit.MILLISECONDS);
LogUtils.i(TAG, "onConnectionStateChange():連接斷開,status = " + status);
mState = State.STATE_DISCONNECT;
} else {
LogUtils.i(TAG, "其它狀態: status = " + status + ", newState = " + newState);
}
}
示例7: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
Log.i(TAG, "Connected to GATT client. Attempting to start service discovery");
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
Log.i(TAG, "Disconnected from GATT client");
mListener.onConnected(false);
}
}
示例8: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
boolean didConnect = false;
NeatleLogger.d("onConnectionStateChange status: " + status + " newState:" + newState);
if (newState == BluetoothGatt.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) {
didConnect = gatt.discoverServices();
}
if (!didConnect) {
gatt.close();
connectionFailed(status);
} else {
connectionSuccess();
}
}
示例9: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
/**
* Callback indicating when GATT client has connected/disconnected to/from a remote GATT server
*
* @param gatt 返回連接建立的gatt對象
* @param status 返回的是此次gatt操作的結果,成功了返回0
* @param newState 每次client連接或斷開連接狀態變化,STATE_CONNECTED 0,STATE_CONNECTING 1,STATE_DISCONNECTED 2,STATE_DISCONNECTING 3
*/
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.d(Tag, "onConnectionStateChange status:" + status + " newState:" + newState);
if (status == 0) {
gatt.discoverServices();
}
}
示例10: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
Log.i(mTAG, "Connected to GATT client. Attempting to start service discovery");
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
Log.i(mTAG, "Disconnected from GATT client");
mIsConnecting = false;
}
}
示例11: onServicesDiscovered
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
Log.i(TAG, "onServicesDiscovered called...");
BluetoothDevice device = gatt.getDevice();
int discoveredServices = gatt.getServices().size();
if(discoveredServices == 0 && isConnected(device)) {
Log.i(TAG, "Re-discovering services. No previous services and is connected");
gatt.discoverServices();
return;
}
broadcastUpdate(ACTION_GATT_CLIENT_SERVICES_DISCOVERED);
}
示例12: scanServices
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
public boolean scanServices(String mac) {
BluetoothGatt bluetoothGatt = checkAndGetGattItem(mac);
boolean result = false;
if (bluetoothGatt != null) {
result = bluetoothGatt.discoverServices();
}
return result;
}
示例13: onMtuChanged
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onMtuChanged (BluetoothGatt gatt, int mtu, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
mGattMtu = mtu;
gatt.discoverServices();
}
}
示例14: onConnected
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
private void onConnected(BluetoothGatt gatt) {
gatt.discoverServices();
bluetoothGatt.put(gatt.getDevice().getAddress(), new BlePair(gatt));
sendBroadcast(
new Intent(DEVICE_CONNECTED)
.putExtra(DEVICE_ADDRESS, gatt.getDevice().getAddress())
);
}
示例15: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //導入方法依賴的package包/類
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.e(LOG_TAG, "onConnectionStateChange from " + status + " to "+ newState + " on peripheral:" + device.getAddress()+" gatt:" + gatt);
this.gatt = gatt;
if (newState == BluetoothGatt.STATE_CONNECTED) {
connected = true;
trytime=0;
// try {
// Thread.sleep(500);
// }catch (Exception e){}
gatt.discoverServices();
sendConnectionEvent(device, "BleManagerConnectPeripheral");
} else if (newState == BluetoothGatt.STATE_DISCONNECTED){
Log.e(LOG_TAG,"connect="+connected+" gatt="+gatt);
if (connected) {
connected = false;
}
if (this.gatt != null) {
this.gatt.close();
this.gatt = null;
}
if(status == 133)
{
if (this.gatt != null) {
this.gatt.close();
this.gatt = null;
}
trytime++;
Log.e(LOG_TAG, "trytime="+trytime);
if(trytime < 2)
{
connect(connectCallback,mActivity);
return;
}
}
trytime=0;
sendConnectionEvent(device, "BleManagerDisconnectPeripheral");
if (connectCallback != null) {
connectCallback.invoke("Connection error");
connectCallback = null;
}
}
}