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


Java BluetoothDevice.getBondState方法代码示例

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


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

示例1: createBondDiscoveredDevices

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
private void createBondDiscoveredDevices() {
    Log.d(TAG, "createBondDiscoveredDevices");
    if (mTargetDevices.size() <= 0) {
        Log.d(TAG, "no new discovered device");
        return;
    }
    for (BluetoothDevice device : mTargetDevices) {
        Log.d(TAG, "discovered device:" + device.getName());

        if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
            Log.d(TAG, "already bonded.");
        } else {
            Log.d(TAG, "try to createBond..");
            boolean result = device.createBond();
            Log.d(TAG, "device.createBond() result: " + result);
        }
    }
}
 
开发者ID:casper-kim,项目名称:androidthings-bluetooth-pairing,代码行数:19,代码来源:MainActivity.java

示例2: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@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,代码行数:23,代码来源:DeviceListActivity.java

示例3: performDeviceFoundAction

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
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,代码行数:21,代码来源:BluetoothHandler.java

示例4: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@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) {

            if (device.getName() != null) {
                bluetoothDevicesAdapter.addDevice(device.getName() + "\n" + device.getAddress());
            }
        }

    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        searchForNewDevices.setEnabled(true);
        searchProgressbar.setVisibility(View.GONE);
        if (pairedDevices.size() == bluetoothDevicesAdapter.getItemCount()) {
            Toast.makeText(BluetoothDevices.this, "No devices found", Toast.LENGTH_SHORT).show();
        }
    }
}
 
开发者ID:Ahmed-Abdelmeged,项目名称:Android-BluetoothMCLibrary,代码行数:25,代码来源:BluetoothDevices.java

示例5: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
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,代码行数:34,代码来源:Nes30Connection.java

示例6: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@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,代码行数:22,代码来源:DeviceListActivity.java

示例7: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@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,代码行数:18,代码来源:DeviceListActivity.java

示例8: onItemClick

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    BluetoothDeviceAdapter deviceAdapter = ((BluetoothDeviceAdapter) parent.getAdapter());
    final BluetoothDevice device =  deviceAdapter.getItem(position);

    if (device.getBondState() == BluetoothDevice.BOND_BONDED && !presenter.getActivePrinter().isEmpty()) {
        final String[] titles = getResources().getStringArray(R.array.printlist_unpaireds);
        UtilsDialog.createAlertDialog(this)
                .setTitle(R.string.choice_make)
                .setSingleChoiceItems(titles, -1, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which){
                            case 0: presenter.unpairDialog(device); break;
                            case 1: presenter.printTest(); break;
                        }
                        dialog.dismiss();
                    }
                })
                .setCancelable(false)
                .show();
    }else {
        presenter.pairDevice(device, this);
    }
}
 
开发者ID:barisatalay,项目名称:thermalprinterhelper,代码行数:26,代码来源:PrinterListActivity.java

示例9: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@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,代码行数:23,代码来源:DeviceListActivity.java

示例10: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@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) {

            bluetoothDevicesAdapter.add(device.getName() + "\n" + device.getAddress());
        }

    } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
        searchForNewDevices.setEnabled(true);
    }
}
 
开发者ID:Ahmed-Abdelmeged,项目名称:Bluetooth-send,代码行数:19,代码来源:BluetoothDevices.java

示例11: ensureServiceChangedEnabled

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
/**
 * 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,代码行数:28,代码来源:BleManager.java

示例12: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@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,代码行数:22,代码来源:MainActivity.java

示例13: isNewDevice

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
/**
 * 判断搜索的设备是新蓝牙设备,且不重复
 * @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,代码行数:17,代码来源:DeviceListFragment.java

示例14: getState

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
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,代码行数:10,代码来源:DevicesAdapter.java

示例15: createBond

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@SuppressLint("NewApi")
private boolean createBond(final BluetoothDevice device) {
    if (device.getBondState() == BluetoothDevice.BOND_BONDED)
        return true;

    boolean result;
    mRequestCompleted = false;

    sendLogBroadcast(LOG_LEVEL_VERBOSE, "Starting pairing...");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt.getDevice().createBond()");
        result = device.createBond();
    } else {
        result = createBondApi18(device);
    }

    // We have to wait until device is bounded
    try {
        synchronized (mLock) {
            while (!mRequestCompleted && !mAborted)
                mLock.wait();
        }
    } catch (final InterruptedException e) {
        loge("Sleeping interrupted", e);
    }

    return result;
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:29,代码来源:DfuBaseService.java


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