當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothDevice.BOND_BONDING屬性代碼示例

本文整理匯總了Java中android.bluetooth.BluetoothDevice.BOND_BONDING屬性的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothDevice.BOND_BONDING屬性的具體用法?Java BluetoothDevice.BOND_BONDING怎麽用?Java BluetoothDevice.BOND_BONDING使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.bluetooth.BluetoothDevice的用法示例。


在下文中一共展示了BluetoothDevice.BOND_BONDING屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: performBondStateChangeAction

private void performBondStateChangeAction(Intent intent) {
    final int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, BluetoothDevice.ERROR);
    final int prevState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, BluetoothDevice.ERROR);
    if (state == BluetoothDevice.BOND_BONDED && prevState == BluetoothDevice.BOND_BONDING) {
        showToast(mContext.getString(R.string.device_paired));
        connectToZephyrDevice();
    } else if (state == BluetoothDevice.BOND_NONE) {
        showToast(mContext.getString(R.string.device_pairing_failure));
    }
}
 
開發者ID:Welloculus,項目名稱:MobileAppForPatient,代碼行數:10,代碼來源:BluetoothHandler.java

示例2: onReceive

public void onReceive(Context context, Intent intent) {
  String action = intent.getAction();
  // Discovery has found a device.
  if (BluetoothDevice.ACTION_FOUND.equals(action)) {
    // Get the BluetoothDevice object and its info from the Intent.
    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    int bondState = device.getBondState();
    String foundName = device.getName();
    String foundAddress = device.getAddress(); // MAC address
    Timber.d("Discovery has found a device: %d/%s/%s", bondState, foundName, foundAddress);
    if (isSelectedDevice(foundAddress)) {
      createBond(device);
    } else {
      Timber.d("Unknown device, skipping bond attempt.");
    }
  } else if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
    int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
    switch (state) {
      case BluetoothDevice.BOND_NONE:
        Timber.d("The remote device is not bonded.");
        break;
      case BluetoothDevice.BOND_BONDING:
        Timber.d("Bonding is in progress with the remote device.");
        break;
      case BluetoothDevice.BOND_BONDED:
        Timber.d("The remote device is bonded.");
        break;
      default:
        Timber.d("Unknown remote device bonding state.");
        break;
    }
  }
}
 
開發者ID:zugaldia,項目名稱:android-robocar,代碼行數:33,代碼來源:Nes30Connection.java

示例3: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
        int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);

        switch (bondState) {
            case BluetoothDevice.BOND_NONE:
                Log.d(TAG, "Bluetooth device not paired!");
                break;

            case BluetoothDevice.BOND_BONDING:
                Log.d(TAG, "Bluetooth device pairing!");
                break;

            case BluetoothDevice.BOND_BONDED:
                Log.d(TAG, "Bluetooth device paired!");
                break;
        }
    }
}
 
開發者ID:m-thu,項目名稱:android-things,代碼行數:20,代碼來源:MainActivity.java

示例4: onReceive

@Override
public void onReceive(final Context context, final Intent intent) {
    // Obtain the device and check it this is the one that we are connected to
    final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    if (!device.getAddress().equals(mDeviceAddress))
        return;

    // Read bond state
    final int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
    if (bondState == BluetoothDevice.BOND_BONDING)
        return;

    mRequestCompleted = true;

    // Notify waiting thread
    synchronized (mLock) {
        mLock.notifyAll();
    }
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:19,代碼來源:DfuBaseService.java

示例5: onDevicePairingEnded

/**
 * {@inheritDoc}
 */
@Override
public void onDevicePairingEnded() {
    if (bluetooth.isPairingInProgress()) {
        BluetoothDevice device = bluetooth.getBoundingDevice();
        switch (bluetooth.getPairingDeviceStatus()) {
            case BluetoothDevice.BOND_BONDING:
                // Still pairing, do nothing.
                break;
            case BluetoothDevice.BOND_BONDED:
                // Successfully paired.
                listener.endLoadingWithDialog(false, device);

                // Updates the icon for this element.
                notifyDataSetChanged();
                break;
            case BluetoothDevice.BOND_NONE:
                // Failed pairing.
                listener.endLoadingWithDialog(true, device);
                break;
        }
    }
}
 
開發者ID:aurasphere,項目名稱:blue-pair,代碼行數:25,代碼來源:DeviceRecyclerViewAdapter.java

示例6: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    if (intent.getAction().equals(BluetoothDevice.ACTION_FOUND)) {
        if((mType == TypeBluetooth.Client && !isConnected)
                || (mType == TypeBluetooth.Server && !mAdressListServerWaitingConnection.contains(device.getAddress()))){

            EventBus.getDefault().post(device);
        }
    }
    else if (intent.getAction().equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED))
    {
            //start it up again!
            scanAllBluetoothDevice();
    }
    else if(intent.getAction().equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)){
        //Log.e("", "===> ACTION_BOND_STATE_CHANGED");
        int prevBondState = intent.getIntExtra(BluetoothDevice.EXTRA_PREVIOUS_BOND_STATE, -1);
        int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE, -1);
        if (prevBondState == BluetoothDevice.BOND_BONDING)
        {
            // check for both BONDED and NONE here because in some error cases the bonding fails and we need to fail gracefully.
            if (bondState == BluetoothDevice.BOND_BONDED || bondState == BluetoothDevice.BOND_NONE )
            {
                //Log.e("", "===> BluetoothDevice.BOND_BONDED");
                EventBus.getDefault().post(new BondedDevice());
            }
        }
    }
}
 
開發者ID:n8fr8,項目名稱:LittleBitLouder,代碼行數:30,代碼來源:BluetoothManager.java

示例7: resolveBondingState

/**
 * Resolve bonding state.
 *
 * @param bondState the bond state
 * @return the string
 */
private static String resolveBondingState(final int bondState) {
    switch (bondState) {
        case BluetoothDevice.BOND_BONDED:
            return "Paired";
        case BluetoothDevice.BOND_BONDING:
            return "Pairing";
        case BluetoothDevice.BOND_NONE:
            return "Unbonded";
        default:
            return "Unknown";
    }
}
 
開發者ID:Twelvelines,項目名稱:AndroidMuseumBleManager,代碼行數:18,代碼來源:BluetoothLeDevice.java

示例8: getState

private String getState(final BluetoothDevice device, final int position) {
	if (mConnectingPosition == position)
		return mConnectingText;
	else if (device.getBondState() == BluetoothDevice.BOND_BONDED)
		return mBondedText;
	else if (device.getBondState() == BluetoothDevice.BOND_BONDING)
		return mBondingText;
	return mAvailableText;
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:9,代碼來源:DevicesAdapter.java

示例9: bondStateToString

protected String bondStateToString(final int state) {
	switch (state) {
		case BluetoothDevice.BOND_NONE:
			return "BOND_NONE";
		case BluetoothDevice.BOND_BONDING:
			return "BOND_BONDING";
		case BluetoothDevice.BOND_BONDED:
			return "BOND_BONDED";
		default:
			return "UNKNOWN";
	}
}
 
開發者ID:runtimeco,項目名稱:Android-DFU-App,代碼行數:12,代碼來源:BleManager.java

示例10: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    String action = intent.getAction();
    BluetoothDevice device = null;
    device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
    if(device!=null){
    }
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
        if (device.getBondState() == BluetoothDevice.BOND_NONE) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", device.getName());
            map.put("type", device.getBluetoothClass().getDeviceClass());
            map.put("device", device);
            if (list.indexOf(map) == -1) {// 防止重複添加
                list.add(map);
                itemAdapter = new MyBluetoothAdapter(context, list);
                searchDeviceLV.setAdapter(itemAdapter);
            }
        }
    } else if (device != null && device.getBondState() == BluetoothDevice.BOND_BONDING) {
        showShortToast("Being paired");
    } else if (device != null && device.getBondState() == BluetoothDevice.BOND_BONDED) {
        pairTVName.setText(device.getName());
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).get("device").equals(device)) {
                pairPosition = i;
                list.remove(i);
                itemAdapter.notifyDataSetChanged();
            }
        }
        showShortToast("Pairing is complete");
    }
}
 
開發者ID:Evan-Galvin,項目名稱:FreeStreams-TVLauncher,代碼行數:34,代碼來源:Bluetooth.java

示例11: getPairingDeviceStatus

/**
 * Returns the status of the current pairing and cleans up the state if the pairing is done.
 *
 * @return the current pairing status.
 * @see BluetoothDevice#getBondState()
 */
public int getPairingDeviceStatus() {
    if (this.boundingDevice == null) {
        throw new IllegalStateException("No device currently bounding");
    }
    int bondState = this.boundingDevice.getBondState();
    // If the new state is not BOND_BONDING, the pairing is finished, cleans up the state.
    if (bondState != BluetoothDevice.BOND_BONDING) {
        this.boundingDevice = null;
    }
    return bondState;
}
 
開發者ID:aurasphere,項目名稱:blue-pair,代碼行數:17,代碼來源:BluetoothController.java

示例12: handleMessage

@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case Comment.SWITCH:
            switch ((int) msg.obj) {
                case BluetoothAdapter.STATE_OFF:
                    nonebound_tv.setText("可用設備(" + DatasEntity.mBluetoothDevices.size() + ")");
                    btnSearch.setChecked(false);
                    clearAdapter();
                    break;
                case BluetoothAdapter.STATE_ON:
                    reswipeAdapter();
                    break;
            }
            break;
        case Comment.FOUND:
            DatasEntity.mBluetoothDevices.add((BluetoothDevice) msg.obj); // 添加到列表
            nonebound_tv.setText("可用設備(" + DatasEntity.mBluetoothDevices.size() + ")");
            mGetarrayAdapter.notifyDataSetChanged();
            ListViewHeightMesure.setAdapterHeight(mLvallDevices);
            break;

        case Comment.FINISHED:
            setTitle("玩藍牙");
            rotate_img.clearAnimation();
            break;

        case Comment.BOND:
            switch ((int) msg.obj) {
                case BluetoothDevice.BOND_BONDING://正在配對
                    DialogUtil.ShowProgress(MainActivity.this, "配對中...");
                    break;
                case BluetoothDevice.BOND_BONDED://配對結束
                    DialogUtil.CancelProgress();
                    clearAdapter();
                    reswipeAdapter();
                    ToastUtil.showShort(MainActivity.this,"連接中...");
                    BluetoothUtil.connectSocket(mHandler);
                    break;
                case BluetoothDevice.BOND_NONE://取消配對/未配對
                    ToastUtil.showShort(MainActivity.this, "已取消配對");
                    break;
            }
            break;
        case Comment.CONNECT:
            ToastUtil.showShort(MainActivity.this,"連接成功!");
            break;

    }
}
 
開發者ID:aiyangtianci,項目名稱:BluetoothAPP,代碼行數:50,代碼來源:MainActivity.java


注:本文中的android.bluetooth.BluetoothDevice.BOND_BONDING屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。