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