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


Java BluetoothDevice.BOND_BONDED属性代码示例

本文整理汇总了Java中android.bluetooth.BluetoothDevice.BOND_BONDED属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothDevice.BOND_BONDED属性的具体用法?Java BluetoothDevice.BOND_BONDED怎么用?Java BluetoothDevice.BOND_BONDED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.bluetooth.BluetoothDevice的用法示例。


在下文中一共展示了BluetoothDevice.BOND_BONDED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
        // Get the BluetoothDevice object from the Intent
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        // If it's already paired, skip it, because it's been listed already
        if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
            mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
        // When discovery is finished, change the Activity title
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        setProgressBarIndeterminateVisibility(false);
        setTitle(R.string.select_device);
        if (mNewDevicesArrayAdapter.getCount() == 0) {
            String noDevices = getResources().getText(R.string.none_found).toString();
            mNewDevicesArrayAdapter.add(noDevices);
        }
    }
}
 
开发者ID:NaOHAndroid,项目名称:Logistics-guard,代码行数:22,代码来源:DeviceListActivity.java

示例2: ensureServiceChangedEnabled

/**
 * When the device is bonded and has the Generic Attribute service and the Service Changed characteristic this method enables indications on this characteristic.
 * In case one of the requirements is not fulfilled this method returns <code>false</code>.
 *
 * @param gatt the gatt device with services discovered
 * @return <code>true</code> when the request has been sent, <code>false</code> when the device is not bonded, does not have the Generic Attribute service, the GA service does not have
 * the Service Changed characteristic or this characteristic does not have the CCCD.
 */
private boolean ensureServiceChangedEnabled(final BluetoothGatt gatt) {
	if (gatt == null)
		return false;

	// The Service Changed indications have sense only on bonded devices
	final BluetoothDevice device = gatt.getDevice();
	if (device.getBondState() != BluetoothDevice.BOND_BONDED)
		return false;

	final BluetoothGattService gaService = gatt.getService(GENERIC_ATTRIBUTE_SERVICE);
	if (gaService == null)
		return false;

	final BluetoothGattCharacteristic scCharacteristic = gaService.getCharacteristic(SERVICE_CHANGED_CHARACTERISTIC);
	if (scCharacteristic == null)
		return false;

	return enableIndications(scCharacteristic);
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:27,代码来源:BleManager.java

示例3: onReceive

@Override
        public void onReceive(Context context, Intent intent)
        {
            String action = intent.getAction();

            // When discovery finds a device
            if (BluetoothDevice.ACTION_FOUND.equals(action))
            {
                // Get the BluetoothDevice object from the Intent
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

                // Get rssi value
                short rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI,  Short.MIN_VALUE);

                // If it's already paired, skip it, because it's been listed already
                if (device.getBondState() != BluetoothDevice.BOND_BONDED)
                {
                    NLog.d( "ACTION_FOUND SPP : " +device.getName() + " address : "+ device.getAddress()+", COD:" + device.getBluetoothClass());

                    mNewDevicesArrayAdapter.add(device.getName() + "\n" + "[RSSI : "+rssi +"dBm] " + device.getAddress());
//                    mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()+"\n Major"+device.getBluetoothClass().toString()+"\nDeviceClass()"+device.getBluetoothClass().getDeviceClass()+"device="+device.getType());

                }
            // When discovery is finished, change the Activity title
            }
            else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
            {
                setProgressBarIndeterminateVisibility(false);
                setTitle(R.string.select_device);

                if (mNewDevicesArrayAdapter.getCount() == 0)
                {
                    String noDevices = getResources().getText(R.string.none_found).toString();
                    mNewDevicesArrayAdapter.add(noDevices);
                }
            }
        }
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:37,代码来源:DeviceListActivity.java

示例4: 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

示例5: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
        // Get the BluetoothDevice object from the Intent
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        // If it's already paired, skip it, because it's been listed already
        if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
            mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
        // When discovery is finished, change the Activity title
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        setTitle(R.string.select_device);
        if (mNewDevicesArrayAdapter.getCount() == 0) {
            String noDevices = getResources().getText(R.string.none_found).toString();
            mNewDevicesArrayAdapter.add(noDevices);
        }
    }
}
 
开发者ID:paulinog,项目名称:SecretTalk,代码行数:21,代码来源:DeviceListActivity.java

示例6: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
            mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        setProgressBarIndeterminateVisibility(false);
        setTitle("Select Paired Device");
        if (mNewDevicesArrayAdapter.getCount() == 0) {
            mNewDevicesArrayAdapter.add("None Found");
        }
    }
}
 
开发者ID:zeevy,项目名称:grblcontroller,代码行数:17,代码来源:DeviceListActivity.java

示例7: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onReceive: Execute");
    String action = intent.getAction();
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        String deviceName = device.getName();
        boolean  paired = device.getBondState() == BluetoothDevice.BOND_BONDED;
        String deviceAddress = device.getAddress();
        short deviceRSSI = intent.getExtras().getShort(BluetoothDevice.EXTRA_RSSI, (short) 0);
        Device mDevice = new Device(deviceName, paired, deviceAddress, deviceRSSI);

        devices.remove(scannedDevice(mDevice));
        devices.add(mDevice);
        deviceAdapter.notifyDataSetChanged();
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        if (devices.size() == 0) {
            Log.d(TAG, "onReceive: No device");
        }
    }
}
 
开发者ID:kevin-vista,项目名称:bluetooth-scanner,代码行数:21,代码来源:MainActivity.java

示例8: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
        // Get the BluetoothDevice object from the Intent
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        // If it's already paired, skip it, because it's been listed already
        if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
            mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
    // When discovery is finished, change the Activity title
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        setProgressBarIndeterminateVisibility(false);
        setTitle(R.string.select_device);
        if (mNewDevicesArrayAdapter.getCount() == 0) {
            String noDevices = getResources().getText(R.string.none_found).toString();
            mNewDevicesArrayAdapter.add(noDevices);
        }
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:22,代码来源:DeviceListActivity.java

示例9: 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

示例10: startPairingSecureBle

/**
 * Checks if device is paired, if true - stops scanning and proceeds with success message,
 * else - starts pairing to the device.
 *
 * @param device Device to pair with.
 */
private void startPairingSecureBle(BluetoothDevice device) {
    logi("###>>>>>>>>>>>>>>>>>>>>> startPairingSecureBle");
    //Check if the device is already bonded
    if(device.getBondState() == BluetoothDevice.BOND_BONDED) {
        logi("Device is already bonded.");
        stopScanning();
        //Get device name from the System settings if present and add to our list
        ConnectedDevice newDev = new ConnectedDevice(newDeviceCode.toUpperCase(),
                newDeviceCode.toUpperCase(), false, newDeviceAddress, 0, null,
                System.currentTimeMillis());
        handlePairingSuccessful(newDev);
    } else {
        logi("device.createBond returns " + device.createBond());
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:21,代码来源:PairingActivity.java

示例11: performDeviceFoundAction

private void performDeviceFoundAction(BluetoothDevice device) {
    dismissProgress();
    String display = device.getAddress();
    if (!TextUtils.isEmpty(device.getName())) {
        display = device.getName();
    }
    showToast(mContext.getString(R.string.found_the_device) + " " + display);
    Log.v(AppUtility.TAG, "Found the device with name : " + device.getName() + " address : " + device.getAddress());
    isDeviceFound = true;
    if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
        connectToZephyrDevice();
    } else {
        showToast(mContext.getString(R.string.device_not_paired));
        try {
            pairDevice(device);
        } catch (Exception e) {
            Log.e(AppUtility.TAG, Log.getStackTraceString(e));
        }
    }
}
 
开发者ID:Welloculus,项目名称:MobileAppForPatient,代码行数:20,代码来源:BluetoothHandler.java

示例12: onConnectionStateChange

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
	String intentAction;
	if (newState == BluetoothProfile.STATE_CONNECTED) {
		Log.i(TAG, "Connected to GATT server.");
		if( gatt.getDevice().getBondState() != BluetoothDevice.BOND_BONDED ) {
			broadcastUpdate(ACTION_NOT_PAIRED);
			gatt.disconnect();
			return;
		}
		Log.i(TAG, "Attempting to start service discovery" );
		mBluetoothGatt.discoverServices();
		connected = true;
		broadcastUpdate(ACTION_GATT_CLIENT_CONNECTED);
	}
	else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
		intentAction = ACTION_GATT_CLIENT_DISCONNECTED;
		Log.i(TAG, "Disconnected from GATT server.");
		broadcastUpdate(intentAction);
		connected = false;
	}
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:22,代码来源:BluetoothClientService.java

示例13: isNewDevice

/**
 * 判断搜索的设备是新蓝牙设备,且不重复
 * @param device
 * @return
 */
private boolean isNewDevice(BluetoothDevice device){
    boolean repeatFlag = false;
    for (BluetoothDevice d :
            deviceList) {
        if (d.getAddress().equals(device.getAddress())){
            repeatFlag=true;
        }
    }
    //不是已绑定状态,且列表中不重复
    return device.getBondState() != BluetoothDevice.BOND_BONDED && !repeatFlag;
}
 
开发者ID:QiaoJim,项目名称:BluetoothStudy,代码行数:16,代码来源:DeviceListFragment.java

示例14: onReceive

public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    
    // When discovery finds a device
    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
        // Get the BluetoothDevice object from the Intent
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        
        // If it's already paired, skip it, because it's been listed already
        if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
            String strNoFound = getIntent().getStringExtra("no_devices_found");
            if(strNoFound == null) 
            	strNoFound = "No devices found";                    
            
        	if(mPairedDevicesArrayAdapter.getItem(0).equals(strNoFound)) {
        		mPairedDevicesArrayAdapter.remove(strNoFound);
        	}
        	mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
        
    // When discovery is finished, change the Activity title
    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        setProgressBarIndeterminateVisibility(false);
        String strSelectDevice = getIntent().getStringExtra("select_device");
        if(strSelectDevice == null) 
        	strSelectDevice = "Select a device to connect";
        setTitle(strSelectDevice);
    }
}
 
开发者ID:voroshkov,项目名称:Chorus-RF-Laptimer,代码行数:29,代码来源:DeviceList.java

示例15: 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


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