本文整理汇总了Java中android.bluetooth.BluetoothDevice.getAddress方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothDevice.getAddress方法的具体用法?Java BluetoothDevice.getAddress怎么用?Java BluetoothDevice.getAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothDevice
的用法示例。
在下文中一共展示了BluetoothDevice.getAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectController
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
public boolean connectController(BluetoothDevice bd) {
// Connect SmartController via BLE
if (m_bleDevice != null && m_bleAddress.length() > 0) {
MessageHandler messageHandler = new MessageHandlerImpl(mHandler);
mDeviceConnector = new BLEDeviceConnector(messageHandler, m_bleAddress);
mDeviceConnector.connect();
return true;
} else {
Log.d("XLight", "not found ble device");
if (bd != null && bd.getAddress().length() > 0) {
m_bleDevice = bd;
m_bleAddress = bd.getAddress();
return connectController();
}
return false;
}
}
示例2: onCharacteristicWriteRequest
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId,
BluetoothGattCharacteristic characteristic, boolean preparedWrite,
boolean responseNeeded, int offset, byte[] value) {
super.onCharacteristicWriteRequest(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value);
mGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, offset, value);
if (mProvClientDev.getPeerDevice().equals(device)) {
if (characteristic.getUuid().compareTo(UUID.fromString(UUID_PB_CHAR_DATA_IN)) == 0)
{
String strAddr=device.getAddress();
byte[] addr = stringToAddress(strAddr);
provServerPduInNative(addr, value);
}
}
}
示例3: listPairedDevices
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
private void listPairedDevices(View view){
mPairedDevices = mBTAdapter.getBondedDevices();
if(mBTAdapter.isEnabled()) {
// put it's one to the adapter
btList = new String[mPairedDevices.size()];
int i=0;
for (BluetoothDevice device : mPairedDevices) {
btList[i] = device.getName() + "\n" + device.getAddress();
//mBTArrayAdapter.add(device.getName() + "\n" + device.getAddress());
i++;
}
//new MaterialDialog.Builder(this).title(R.string.connect_bluetooth).adapter(mBTArrayAdapter, null).show();
showSnackbar("Show Paired Devices");
showBluetoothDeviceList();
//Toast.makeText(getApplicationContext(), "Show Paired Devices", Toast.LENGTH_SHORT).show();
}
else{
showSnackbar("Bluetooth not on");
}
//Toast.makeText(getApplicationContext(), "Bluetooth not on", Toast.LENGTH_SHORT).show();
}
示例4: listPairedDevices
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
/**
* Organizes and sends to Godot all external paired devices
*/
private void listPairedDevices() {
String localDeviceName = localBluetooth.getName();
String localDeviceAddress = localBluetooth.getAddress();
Set<BluetoothDevice> pairedDevices = localBluetooth.getBondedDevices();
if(pairedDevices.size() > 0) {
pairedDevicesAvailable = (Object []) pairedDevices.toArray();
int externalDeviceID = 0;
for (BluetoothDevice device : pairedDevices) {
String externalDeviceName = device.getName();
String externalDeviceAddress = device.getAddress();
GodotLib.calldeferred(instanceId, "_on_single_device_found", new Object[]{ externalDeviceName, externalDeviceAddress, externalDeviceID });
externalDeviceID += 1;
}
pairedDevicesListed = true;
}
}
示例5: addDevice
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
public void addDevice(BluetoothDevice device) {
if(!mLeDevices.contains(device)) {
mLeDevices.add(device);
DeviceItem deviceItem = new DeviceItem(device.getName(), device.getAddress());
data.add(deviceItem);
notifyDataSetChanged();
}
}
示例6: onFind
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
public void onFind(BluetoothDevice device, boolean saved) {
String name = device.getName() == null || device.getName().equals("") ? device.getAddress() : device.getName();
if (!foundDevices.containsKey(name)) {
spnDevicesAdapter.add(new BtFoundDevice(name, device));
foundDevices.put(name, true);
}
}
示例7: getPairedDeviceAddress
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
public String[] getPairedDeviceAddress() {
int c = 0;
Set<BluetoothDevice> devices = mBluetoothAdapter.getBondedDevices();
String[] address_list = new String[devices.size()];
for(BluetoothDevice device : devices) {
address_list[c] = device.getAddress();
c++;
}
return address_list;
}
示例8: getDeviceName
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
/**
* Gets the name of a device. If the device name is not available, returns the device address.
*
* @param device the device whose name to return.
* @return the name of the device or its address if the name is not available.
*/
public static String getDeviceName(BluetoothDevice device) {
String deviceName = device.getName();
if (deviceName == null) {
deviceName = device.getAddress();
}
return deviceName;
}
示例9: getCarIdForBTDevice
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
/**
* Check if the bluetooth device is linked with a car.
*
* @param ctx the context
* @param device the bluetooth device
* @return -1 if no linked car, DEF_CAR._id if a linked car exists
*/
private long getCarIdForBTDevice(Context ctx, BluetoothDevice device) {
long retVal = -1L;
if (device != null) {
String deviceMAC = device.getAddress();
//check if this device is linked with a car
if (deviceMAC == null || deviceMAC.length() == 0) {
return retVal;
}
String[] selArgs = {deviceMAC};
DBAdapter mDb = new DBAdapter(ctx);
Cursor c = mDb.query(
DBAdapter.TABLE_NAME_BTDEVICE_CAR,
DBAdapter.COL_LIST_BTDEVICECAR_TABLE,
"1 = 1 " + DBAdapter.WHERE_CONDITION_ISACTIVE + " AND "
+ DBAdapter.sqlConcatTableColumn(DBAdapter.TABLE_NAME_BTDEVICE_CAR, DBAdapter.COL_NAME_BTDEVICECAR__MACADDR)
+ " = ?", selArgs, DBAdapter.COL_NAME_GEN_ROWID + " DESC");
if (c == null) {
return retVal;
}
if (c.moveToFirst()) { //linked car exist
retVal = c.getLong(DBAdapter.COL_POS_BTDEVICECAR__CAR_ID);
}
try {
c.close();
mDb.close();
}
catch (Exception ignored) {
}
}
return retVal;
}
示例10: getView
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = mInflater.inflate(R.layout.item_bluetoothdevice, parent, false);
holder = null;
BluetoothDevice item = allData.get(position);
if (convertView == null) {
holder = new ViewHolder(view);
view.setTag(holder);
} else {
view = convertView;
holder = ((ViewHolder) view.getTag());
}
holder.item_bluetoothdevice_bg.setId(position);
holder.item_bluetoothdevice_bg.setBackgroundResource(R.color.generalWhite);
// if (item.getBondState() != BluetoothDevice.BOND_BONDED || deviceAddress.isEmpty()) {
if (deviceAddress.isEmpty() && deviceAddress == item.getAddress()) {
holder.item_bluetoothdevice_image.setColorFilter(ContextCompat.getColor(context,R.color.generalGreen));
}else{
holder.item_bluetoothdevice_image.setColorFilter(null);
}
if(selectedList.contains(position))
holder.item_bluetoothdevice_bg.setBackgroundResource(R.color.listview_item_selected);
holder.item_bluetoothdevice_text.setText(item.getName() == null?"No Name":item.getName() + "\n" + item.getAddress());
return view;
}
示例11: foundDevice
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
public boolean foundDevice (BluetoothDevice device)
{
boolean resultIsNew = false;
if (device != null && device.getName() != null &&
(device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_HANDHELD_PC_PDA ||
device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.COMPUTER_PALM_SIZE_PC_PDA ||
device.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.PHONE_SMART)) {
if (mPairedDevicesOnly && device.getBondState() == BluetoothDevice.BOND_NONE)
return false; //we can only support paired devices
if (!mFoundDevices.containsKey(device.getAddress())) {
mFoundDevices.put(device.getAddress(), device);
resultIsNew = true;
if (mNearbyListener != null) {
Neighbor neighbor = new Neighbor(device.getAddress(),device.getName(),Neighbor.TYPE_BLUETOOTH);
mNearbyListener.foundNeighbor(neighbor);
}
}
if (clientThreads.containsKey(device.getAddress()))
if (clientThreads.get(device.getAddress()).isAlive())
return false; //we have a running thread here people!
log("Found device: " + device.getName() + ":" + device.getAddress());
ClientThread clientThread = new ClientThread(device, mHandler, mPairedDevicesOnly);
clientThread.start();
clientThreads.put(device.getAddress(), clientThread);
}
return resultIsNew;
}
示例12: connectNearbyBluetoothDevice
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
private void connectNearbyBluetoothDevice(){
mPairedDevices = mBTAdapter.getBondedDevices();
if(mBTAdapter.isEnabled()) {
// put it's one to the adapter
btList = new String[mPairedDevices.size()];
int i=0;
for (BluetoothDevice device : mPairedDevices) {
btList[i] = device.getName() + "\n" + device.getAddress();
//mBTArrayAdapter.add(device.getName() + "\n" + device.getAddress());
if(device.getName().startsWith("nearby")){
connectBluetoothDevice(btList[i]);
break;
}
i++;
}
//new MaterialDialog.Builder(this).title(R.string.connect_bluetooth).adapter(mBTArrayAdapter, null).show();
// showSnackbar("Show Paired Devices");
// showBluetoothDeviceList();
//Toast.makeText(getApplicationContext(), "Show Paired Devices", Toast.LENGTH_SHORT).show();
}
else{
// showSnackbar("Bluetooth not on");
}
}
示例13: onConnectionStateChange
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
if (mProvClientDev != null) {
if (mProvClientDev.getPeerDevice() != null) {
if (mProvClientDev.getPeerDevice().equals(device)) {
String strAddr = device.getAddress();
byte[] addr = stringToAddress(strAddr);
if (newState == BluetoothProfile.STATE_CONNECTED) {
if (mProvClientDev.getConnectionState() == PeerDevice.STATE_DISCONNECTED) {
mProvClientDev.setPeerDevice(device);
mProvClientDev.setConnectionState(PeerDevice.STATE_CONNECTED);
if (D) {
Log.i(TAG, "Connected to GATT Client.");
}
connectionChangedNative(addr, true, status);
}
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
mProvClientDev.setConnectionState(PeerDevice.STATE_DISCONNECTED);
if (D) {
Log.i(TAG, "Disconnected from GATT Client.");
}
advertiseStop();
connectionChangedNative(addr, false, status);
mGattServer.close();
}
}
}
}
}
示例14: onReceive
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Discovery has found a device. Get the BluetoothDevice
// object and its info from the Intent.
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
Log.w(TAG, "New Device Found = " + device.getName());
if(isNanoHubDevice(device)){
myDevices.add(device);
tvDevice.setText("Device: " + device.getName() + "\t" + device.getAddress());
deviceAddress = device.getAddress();
}
}
}
示例15: onItemClick
import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
BluetoothDevice bluetoothDevice = this.deviceList.get(position);
if (bluetoothDevice.getBondState() != BluetoothDevice.BOND_BONDED)
{
Toast.makeText(this, "Bluetooth device not paired", Toast.LENGTH_SHORT).show();
}
String address = bluetoothDevice.getAddress();
Intent intent = new Intent();
intent.putExtra("address", address);
this.setResult(RESULT_OK, intent);
this.finish();
}