當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。