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


Java BluetoothDevice类代码示例

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


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

示例1: findBluetoothDevice

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
void findBluetoothDevice(BluetoothAdapter myBluetoothAdapter,
                                    String filter) {
    Log.d(TAG, "(*) Initialising Bluetooth connection for device: " + filter);

    if(myBluetoothAdapter.isEnabled()) {
        for (BluetoothDevice pairedDevice : myBluetoothAdapter.getBondedDevices()) {
            if (pairedDevice.getName().contains(filter /*Like MI*/)) {
                Log.d(TAG, "\tDevice Name: " +  pairedDevice.getName());
                Log.d(TAG, "\tDevice MAC: " + pairedDevice.getAddress());

                activeDevice =  pairedDevice;
                break;
            }
        }
    }

    Log.d(TAG, "\tDidnt find any device!");
}
 
开发者ID:yonixw,项目名称:mi-band-2,代码行数:19,代码来源:BLEMiBand2Helper.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:haraldh,项目名称:iconsole-android,代码行数:23,代码来源:DeviceListActivity.java

示例3: connect

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
@ReactMethod
public void connect(String peripheralUUID, Callback callback) {
	Log.d(LOG_TAG, "Connect to: " + peripheralUUID );

	synchronized(peripherals) {
		Peripheral peripheral = peripherals.get(peripheralUUID);
		Log.e(LOG_TAG, "peripheral " + peripheral);
		if (peripheral == null) {
			if (peripheralUUID != null) {
				peripheralUUID = peripheralUUID.toUpperCase();
			}
			if (BluetoothAdapter.checkBluetoothAddress(peripheralUUID)) {
				BluetoothDevice device = bluetoothAdapter.getRemoteDevice(peripheralUUID);
				peripheral = new Peripheral(device, reactContext);
				peripherals.put(peripheralUUID, peripheral);
			} else {
				callback.invoke("Invalid peripheral uuid");
				return;
			}
		}
		peripheral.connect(callback, reactContext!=null?getCurrentActivity():context);
	}
}
 
开发者ID:lenglengiOS,项目名称:react-native-blue-manager,代码行数:24,代码来源:BleManager.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) {
            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,项目名称:buildAPKsSamples,代码行数:23,代码来源:DeviceListActivity.java

示例5: onReceive

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
@Override
public void onReceive(Context ctx, Intent intent) {
	String action = intent.getAction();
	if (action.equals(DISCOVERY_FINISHED)) {
		LOG.info("Discovery finished");
		ctx.unregisterReceiver(this);
		finished.countDown();
	} else if (action.equals(FOUND)) {
		BluetoothDevice d = intent.getParcelableExtra(EXTRA_DEVICE);
		if (LOG.isLoggable(INFO)) {
			LOG.info("Discovered device: " +
					scrubMacAddress(d.getAddress()));
		}
		addresses.add(d.getAddress());
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:17,代码来源:DroidtoothPlugin.java

示例6: getBondedDevices

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
@ProtoMethod(description = "Send bluetooth serial message", example = "")
@ProtoMethodParam(params = {"string"})
public NativeArray getBondedDevices() {
    start();

    Set<BluetoothDevice> listDevices = mAdapter.getBondedDevices();
    MLog.d(TAG, "listDevices " + listDevices);
    int listSize = listDevices.size();
    ProtocoderNativeArray array = new ProtocoderNativeArray(listSize);
    MLog.d(TAG, "array " + array);


    int counter = 0;
    for (BluetoothDevice b : listDevices) {
        MLog.d(TAG, "bt " + b);

        ReturnObject btDevice = new ReturnObject();
        btDevice.put("name", b.getName());
        btDevice.put("mac", b.getAddress());

        array.addPE(counter++, btDevice);
    }

    return array;
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:26,代码来源:PBluetooth.java

示例7: ConnectThread

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
public ConnectThread(BluetoothDevice device, boolean secure) {
    mmDevice = device;
    BluetoothSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    try {
        if (secure) {
            tmp = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE);
        } else {
            tmp = device.createInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);
        }
    } catch (IOException | NullPointerException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
    }
    mmSocket = tmp;
    mState = STATE_CONNECTING;
}
 
开发者ID:zeevy,项目名称:grblcontroller,代码行数:18,代码来源:SerialThreadService.java

示例8: isBluetoothHeadsetAvailable

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
public boolean isBluetoothHeadsetAvailable() {
	ensureInit();
	if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled() && mAudioManager != null && mAudioManager.isBluetoothScoAvailableOffCall()) {
		boolean isHeadsetConnected = false;
		if (mBluetoothHeadset != null) {
			List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices();
			mBluetoothDevice = null;
			for (final BluetoothDevice dev : devices) {    
				if (mBluetoothHeadset.getConnectionState(dev) == BluetoothHeadset.STATE_CONNECTED) {
					mBluetoothDevice = dev;
					isHeadsetConnected = true;
					break;
				}
			}
			Log.d(isHeadsetConnected ? "[Bluetooth] Headset found, bluetooth audio route available" : "[Bluetooth] No headset found, bluetooth audio route unavailable");
		}
		return isHeadsetConnected;
	}
	
	return false;
}
 
开发者ID:treasure-lau,项目名称:Linphone4Android,代码行数:22,代码来源:BluetoothManager.java

示例9: createBondApi18

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
private boolean createBondApi18(final BluetoothDevice device) {
/*
 * There is a createBond() method in BluetoothDevice class but for now it's hidden. We will call it using reflections. It has been revealed in KitKat (Api19)
 */
      try {
          final Method createBond = device.getClass().getMethod("createBond");
          if (createBond != null) {
              sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt.getDevice().createBond() (hidden)");
              return (Boolean) createBond.invoke(device);
          }
      } catch (final Exception e) {
          Log.w(TAG, "An exception occurred while creating bond", e);
          Log.e(TAG, e.toString());
      }

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

示例10: unpairBondedDevices

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
private void unpairBondedDevices() {
    Log.d(TAG, "unpairBondedDevices");
    if (mBluetoothAdapter != null) {
        Set<BluetoothDevice> bondedDevices = mBluetoothAdapter.getBondedDevices();
        for (BluetoothDevice device : bondedDevices) {
            Log.d(TAG, "bonded device:" + device.getName());
            if (TARGET_DEVICE_NAME.contains(device.getName())) {
                unpairDevice(device);
            } else {
                Log.d(TAG, "it is not target device");
            }
        }
    } else {
        Log.d(TAG, "mBluetoothAdapter!=null");
    }
}
 
开发者ID:casper-kim,项目名称:androidthings-bluetooth-pairing,代码行数:17,代码来源:MainActivity.java

示例11: connect

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
/**
 * Start the ConnectThread to initiate a connection to a remote device.
 *
 * @param device The BluetoothDevice to connect
 * @param secure Socket Security type - Secure (true) , Insecure (false)
 */
public synchronized void connect(BluetoothDevice device, boolean secure) {
    Log.d(TAG, "connect to: " + device);

    // Cancel any thread attempting to make a connection
    if (mState == STATE_CONNECTING) {
        if (mConnectThread != null) {
            mConnectThread.cancel();
            mConnectThread = null;
        }
    }

    // Cancel any thread currently running a connection
    if (mConnectedThread != null) {
        mConnectedThread.cancel();
        mConnectedThread = null;
    }

    // Start the thread to connect with the given device
    mConnectThread = new ConnectThread(device, secure);
    mConnectThread.start();
    // Update UI title
    updateUserInterfaceTitle();
}
 
开发者ID:alexmerz,项目名称:dab-iot,代码行数:30,代码来源:BluetoothChatService.java

示例12: ConnectBluetoothThread

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
public ConnectBluetoothThread(BluetoothDevice device, BluetoothAdapter mBluetoothAdapter, Handler handler) {
    // Use a temporary object that is later assigned to mmSocket,
    // because mmSocket is final
    this.mBluetoothAdapter=mBluetoothAdapter;
    this.handler=handler;
    mmDevice = device;

    BluetoothSocket tmp = null;
    msg=new Message();

    // Get a BluetoothSocket to connect with the given BluetoothDevice
    try {
        // MY_UUID is the app's UUID string, also used by the server code
        String uuid="00001101-0000-1000-8000-00805f9b34fb";
        tmp = device.createRfcommSocketToServiceRecord(UUID.fromString(uuid));
    } catch (IOException e) {
        Log.d(TAG, "ConnectBluetoothThread: 初始化uuid错误");
    }
    mmSocket = tmp;
}
 
开发者ID:Axe-Ishmael,项目名称:Blockly,代码行数:21,代码来源:ConnectBluetoothThread.java

示例13: onListItemClick

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    final BluetoothDevice device = devicesListAdapter.getDevice(position);
    if (device == null) return;
    
    if (scanningBleDevices) {
        bluetoothAdapter.stopLeScan(mLeScanCallback);
        scanningBleDevices = false;
    }
    
    final Intent intent = new Intent();
    intent.putExtra(EXTRAS_DEVICE_NAME, device.getName());
    intent.putExtra(EXTRAS_DEVICE_ADDRESS, device.getAddress());
    setResult(Activity.RESULT_OK, intent);
    finish();
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:17,代码来源:WatchSelectorActivity.java

示例14: onListItemClick

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@SuppressWarnings("deprecation")
protected void onListItemClick(ListView l, View v, int position, long id) {
    final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
    if (device == null) return;
    final Intent intent = new Intent(this, DeviceControlActivity.class);
    intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName());
    intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
    if (mScanning) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mBluetoothLeScanner.stopScan(new ScanCallback() {});
        } else {
            mBluetoothAdapter.stopLeScan(mLeScanCallback);
        }
        mScanning = false;
    }
    startActivity(intent);
}
 
开发者ID:igrow-systems,项目名称:igrow-android,代码行数:20,代码来源:DeviceScanActivity.java

示例15: ConnectedThread

import android.bluetooth.BluetoothDevice; //导入依赖的package包/类
public ConnectedThread(BluetoothSocket socket, BluetoothDevice device) {
    MLog.d(TAG, "create ConnectedThread");
    mmSocket = socket;
    mmDevice = device;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        Log.e(TAG, "temp sockets not created", e);
    }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:19,代码来源:PBluetoothClient.java


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