当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothGatt.discoverServices方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:22,代码来源:BTLEAdt.java

示例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();
    }
}
 
开发者ID:e-regular-games,项目名称:arduator,代码行数:19,代码来源:ArduinoCommBle.java

示例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);
}
 
开发者ID:SPINremote,项目名称:sdc-1-quickstart-android,代码行数:28,代码来源:MainActivity.java

示例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;
    }
}
 
开发者ID:yonixw,项目名称:mi-band-2,代码行数:19,代码来源:BLEMiBand2Helper.java

示例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());
    }
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:15,代码来源:BluetoothUtilImpl.java

示例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);
    }
}
 
开发者ID:TommyFen,项目名称:NaiveDemos,代码行数:39,代码来源:BleOperationService.java

示例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);
    }
}
 
开发者ID:Nilhcem,项目名称:blefun-androidthings,代码行数:11,代码来源:GattClient.java

示例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();
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:16,代码来源:Device.java

示例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();
    }
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:15,代码来源:BleActivity.java

示例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;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:11,代码来源:TitagSensorEntity.java

示例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);
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:13,代码来源:BluetoothClientService.java

示例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;
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:9,代码来源:UdooBluService.java

示例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();
	}
}
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:8,代码来源:JniCallbacks.java

示例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())
  );
}
 
开发者ID:drfonfon,项目名称:ITagAntiLost,代码行数:9,代码来源:BleService.java

示例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;
			}

		}

	}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:56,代码来源:Peripheral.java


注:本文中的android.bluetooth.BluetoothGatt.discoverServices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。