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


Java BluetoothDevice.getName方法代码示例

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


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

示例1: onResume

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
protected void onResume() {
	super.onResume();
	if (!mBluetoothAdapter.isEnabled())return;
	if (mBlthChatUtil != null) {
		// 只有国家是state_none,我们知道,我们还没有开始
		if (mBlthChatUtil.getState() == BluetoothChatUtil.STATE_NONE) {
			// 启动蓝牙聊天服务
			mBlthChatUtil.startListen();
		}else if (mBlthChatUtil.getState() == BluetoothChatUtil.STATE_CONNECTED){
			BluetoothDevice device = mBlthChatUtil.getConnectedDevice();
			if(null != device && null != device.getName()){
				mBtConnectState.setText("已成功连接到设备" + device.getName());
			}else {
				mBtConnectState.setText("已成功连接到设备");
			}
		}
	}
}
 
开发者ID:BittleDragon,项目名称:BluetoothChatDemo,代码行数:20,代码来源:ServerActivity.java

示例2: scanNetworks

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@ProtoMethod(description = "Scan bluetooth networks. Gives back the name, mac and signal strength", example = "")
@ProtoMethodParam(params = {"function(name, macAddress, strength)"})
public void scanNetworks(final ReturnInterface callbackfn) {
    MLog.d(TAG, "scanNetworks");
    start();

    mAdapter.startDiscovery();
    BroadcastReceiver mReceiver = new BroadcastReceiver() {
        @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);

                int rssi = intent.getShortExtra(BluetoothDevice.EXTRA_RSSI, Short.MIN_VALUE);

                ReturnObject o = new ReturnObject();
                String name = device.getName();
                if (name == null) name = "";

                o.put("name", name);
                o.put("mac", device.getAddress());
                o.put("strength", rssi);
                callbackfn.event(o);
            }
        }
    };

    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    getContext().registerReceiver(mReceiver, filter);

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

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

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

示例5: onStartCommand

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
	if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
		throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");

	mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);

	// notify user about changing the state to CONNECTING
	final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
	broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
	LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);

	final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
	final BluetoothAdapter adapter = bluetoothManager.getAdapter();
	final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
	mDeviceName = device.getName();

	mBleManager.connect(device);
	return START_REDELIVER_INTENT;
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:21,代码来源:BleProfileService.java

示例6: 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();
}
 
开发者ID:pooi,项目名称:Nearby,代码行数:24,代码来源:RecordVitalSignActivity.java

示例7: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent)
{
	int state = intent.getIntExtra("android.bluetooth.a2dp.extra.SINK_STATE", -1);
	BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
	String action = intent.getAction();
	String name = device != null ? device.getName() : "None";

	Log.d(TAG, String.format("Sink State: %d; Action: %s; Device: %s", state, action, name));

	boolean actionConnected = false;
	boolean actionDisconnected = false;

	if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action))
	{
		actionConnected = true;
	}
	else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) || BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action))
	{
		actionDisconnected = true;
	}

	boolean connected = state == android.bluetooth.BluetoothA2dp.STATE_CONNECTED || actionConnected;
	boolean disconnected = state == android.bluetooth.BluetoothA2dp.STATE_DISCONNECTED || actionDisconnected;

	if (connected)
	{
		Log.i(TAG, "Connected to Bluetooth device, requesting media button focus.");
		Util.registerMediaButtonEventReceiver(context);
	}

	if (disconnected)
	{
		Log.i(TAG, "Disconnected from Bluetooth device, requesting pause.");
		context.sendBroadcast(new Intent(DownloadServiceImpl.CMD_PAUSE));
	}
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:38,代码来源:BluetoothIntentReceiver.java

示例8: onDeviceFound

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
private void onDeviceFound(BluetoothDevice device) {
    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)) {
        subscriber.onNext(new BluetoothPeer(device));
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:9,代码来源:BluetoothFinder.java

示例9: getDeviceOs

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
public static String getDeviceOs(BluetoothDevice device) {
    String macPrefix = device.getAddress().substring(0, 8);
    int majorDeviceClass = device.getBluetoothClass().getMajorDeviceClass();
    if (Manuf.APPLE.contains(macPrefix)) {
        if (majorDeviceClass == 256) {
            return "osx";
        }
        if (majorDeviceClass == 512) {
            return "ios";
        }
        if (!(majorDeviceClass != 7936 || device.getName() == null || device.getName().toLowerCase().contains("mac"))) {
            return "ios";
        }
    }
    if (Manuf.SAMSUNG.contains(macPrefix)) {
        if (majorDeviceClass == 512) {
            return "android";
        }
        if (majorDeviceClass == 1792) {
            return "tizen";
        }
        if (device.getName() == null || !device.getName().contains("TV")) {
            return "samsung";
        }
        return "tizen";
    } else if (device.getName() != null && device.getName().contains("Gear")) {
        return "tizen";
    } else {
        if (majorDeviceClass == 512 && Manuf.ANDROIDS.contains(macPrefix)) {
            return "android";
        }
        if (majorDeviceClass == 256 && !Manuf.APPLE.contains(macPrefix)) {
            return "pc";
        }
        if (majorDeviceClass != 512 || Manuf.APPLE.contains(macPrefix)) {
            return null;
        }
        return "smartphone";
    }
}
 
开发者ID:Xsafe,项目名称:BlueBorne,代码行数:41,代码来源:bluebourne.java

示例10: onResume

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
protected void onResume() {
    super.onResume();
    if (mBlthChatUtil != null) {
        if (mBlthChatUtil.getState() == BluetoothChatUtil.STATE_CONNECTED) {
            BluetoothDevice device = mBlthChatUtil.getConnectedDevice();
            if (null != device && null != device.getName()) {
                mBtConnectState.setText("已成功连接到设备" + device.getName());
            } else {
                mBtConnectState.setText("已成功连接到设备");
            }
        }
    }
}
 
开发者ID:BittleDragon,项目名称:BluetoothChatDemo,代码行数:15,代码来源:ClientActivity.java

示例11: onReceive

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(BluetoothDevice.ACTION_FOUND)) {
        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        Log.d(TAG, "New Bluetooth device found: " + device.getName() +
                " (" + device.getAddress() + ")");

        if ((device.getName() != null && device.getName().equals(HC05_NAME))
                || device.getAddress().equals(HC05_MAC)) {
            mBluetoothAdapter.cancelDiscovery();
            device.setPin(HC05_PIN);
            device.createBond();
        }
    }
}
 
开发者ID:m-thu,项目名称:android-things,代码行数:16,代码来源:MainActivity.java

示例12: btA2dpDisconnect

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Rpc(description = "Disconnects a device from A2DP profile.")
public void btA2dpDisconnect(String deviceAddress) throws Throwable {
    BluetoothDevice device = getConnectedBluetoothDevice(deviceAddress);
    Utils.invokeByReflection(sA2dpProfile, "disconnect", device);
    if (!Utils.waitUntil(
            () -> sA2dpProfile.getConnectionState(device) == BluetoothA2dp.STATE_DISCONNECTED,
            120)) {
        throw new BluetoothA2dpSnippetException(
                "Failed to disconnect device "
                        + device.getName()
                        + "|"
                        + device.getAddress()
                        + " from A2DP profile within 2min.");
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:16,代码来源:BluetoothA2dpSnippet.java

示例13: 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();
    }
}
 
开发者ID:skydoves,项目名称:MagicLight-Controller,代码行数:9,代码来源:LeDeviceListAdapter.java

示例14: connect

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public synchronized void connect(String address) {
 if (mBluetoothAdapter == null || address == null) {
  NLog.w("BluetoothAdapter not initialized or unspecified address.");
  this.responseMsg(new PenMsg(PenMsgType.PEN_CONNECTION_FAILURE));
  return;
 }

 if (penAddress != null)
 {
  if (this.penStatus == CONN_STATUS_AUTHORIZED)
  {
   responseMsg(new PenMsg(PenMsgType.PEN_ALREADY_CONNECTED));
   return;
  }
  else if (this.penStatus != CONN_STATUS_IDLE)
  {
   return;
  }
 }

    final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
    if (device == null) {
        NLog.w("Device not found.  Unable to connect.");
        this.responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE ) );
        return;
    }

    if ( device.getType() != BluetoothDevice.DEVICE_TYPE_LE )
    {
        NLog.w("MacAddress is not Bluetooth LE Type");
        this.responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE ) );
        return;
    }

 if ( this.penStatus != CONN_STATUS_IDLE ) {
  responseMsg(new PenMsg(PenMsgType.PEN_CONNECTION_FAILURE));
  return;
 }

 this.penAddress = address;
    onConnectionTry();
 responseMsg(new PenMsg(PenMsgType.PEN_CONNECTION_TRY));

    this.penBtName = device.getName();

    this.watchDog = new Timer();
    this.watchDogTask = new TimerTask() {
        @Override
        public void run() {
            watchDogAlreadyCalled = true;
            NLog.d("Run WatchDot : connect failed");
            responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE) );
            onDisconnected();
            close();
        }
    };

    this.watchDogAlreadyCalled = false;
    this.mBluetoothGatt = device.connectGatt(context, false, mBluetoothGattCallback);
 try {
  // schedule이 시작전에 connectGatt가 불려서 Cancel이 되어버리는 경우에 대한 exception처리
  // 커넥션 이후엔 여기에 문제가 생겨도 지장없음.
  this.watchDog.schedule(watchDogTask, 3000);  // 3초
 }
 catch (Exception e)
 {
  e.printStackTrace();
 }
    NLog.d("Trying to create a new connection.");
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:72,代码来源:BTLEAdt.java

示例15: connect

import android.bluetooth.BluetoothDevice; //导入方法依赖的package包/类
@Override
public synchronized void connect( String address )
{
       mIsRegularDisconnect = false;
       if(this.penAddress != null)
       {
           if(status == CONN_STATUS_AUTHORIZED)
           {
               responseMsg( new PenMsg( PenMsgType.PEN_ALREADY_CONNECTED));
               return;
           }
           else if(status != CONN_STATUS_IDLE)
           {
               return;
           }
       }

       boolean ret;
       try {
           ret = isAvailableDevice( address );
       } catch (BLENotSupportedException e) {
           ret = false;
       }

       if ( !ret )
       {
           NLog.e( "[BTAdt] Your device is not allowed." );

           this.responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE ) );
           return;
       }

       if ( status != CONN_STATUS_IDLE )
       {
           this.responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE ) );
           return;
       }
       this.penAddress = address;
       onConnectionTry();
       responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_TRY));

       NLog.i( "[BTAdt] connect device : " + address );

       BluetoothDevice device = getBluetoothAdapter().getRemoteDevice( address );
       this.penBtName = device.getName();


       mConnectThread = new ConnectThread( device );
       mConnectThread.start();
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:51,代码来源:BTAdt.java


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