本文整理汇总了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;
}
}
}