Best code examples for Android BluetoothDevice class (android.bluetooth.BluetoothDevice)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android BluetoothDevice class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android BluetoothDevice examples from Open Source projects
This code example shows how to use the following methods: getAddress, getName, getAlias
 
    private String mAddress;
 
    BluetoothTriggerPreference(Context context, BluetoothDevice device) {
        super(context);
        mAddress = device.getAddress();
        if (device.getAlias() != null) {
            setTitle(device.getAlias());
        } else { 
            setTitle(device.getName());
        } 
    } 
 
    BluetoothTriggerPreference(Context context, String name, String address) {
        super(context);
        mAddress = address;
        setTitle(name);
    } 
 
    public String getAddress() {
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getAddress, getBondState, getName
		public void onReceive(final Context pContext, final Intent pIntent) { 
			final String action = pIntent.getAction(); 
 
			if (action.equals(BluetoothDevice.ACTION_FOUND)) { 
				final BluetoothDevice device = pIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
				if (device.getBondState() != BluetoothDevice.BOND_BONDED) { 
					BluetoothListDevicesActivity.this.mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress()); 
				} 
			} else if (action.equals(BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) { 
				BluetoothListDevicesActivity.this.setProgressBarIndeterminateVisibility(false); 
				BluetoothListDevicesActivity.this.setTitle("Select a device to connect..."); 
				if (BluetoothListDevicesActivity.this.mNewDevicesArrayAdapter.getCount() == 0) { 
					BluetoothListDevicesActivity.this.mNewDevicesArrayAdapter.add("No devices found!"); 
				} 
			} 
		} 
	}; 
 
 
	// =========================================================== 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: createRfcommSocketToServiceRecord, getAddress, getName
            Log.i(TAG, getId() + ":begin mConnectThread");
            BluetoothSocket tmp = null;
            // Always cancel discovery because it will slow down a connection 
 
            try { 
                tmp = mmDevice.createRfcommSocketToServiceRecord(BT_UUID);
            } catch (IOException e) {
                Log.e(TAG, "Socket create() failed", e);
                return; 
            } 
            mmSocket = tmp;
            // Make a connection to the BluetoothSocket 
            if (mAdapter.isEnabled()) mAdapter.cancelDiscovery();
            try { 
                // This is a blocking call and will only return on a 
                // successful connection or an exception 
                if (D)  Log.d(TAG, getId() + ":Connecting to socket...");
                mmSocket.connect();
                if (D) Log.d(TAG, "connected with remote device: "
                        + mmDevice.getName() + " at address " + mmDevice.getAddress());

7
CodeRank
This code example shows how to use the following methods: createRfcommSocketToServiceRecord
            // Get a BluetoothSocket for a connection with the 
            // given BluetoothDevice 
            try { 
//                Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); 
//                tmp = (BluetoothSocket) m.invoke(device, 1); 
                tmp = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE);
            } catch (Exception e) {
                e.printStackTrace();
                Log.e(TAG, "Socket Type: " + mSocketType + " create() failed", e);
            } 
            mmSocket = tmp;
        } 
 
        public void run() { 
            Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType);
            setName("ConnectThread" + mSocketType);
 
            // Always cancel discovery because it will slow down a connection 
            mAdapter.cancelDiscovery();
 
Full Snippet Info
6
CodeRank
This code example shows how to use the following methods: createInsecureRfcommSocketToServiceRecord, createRfcommSocketToServiceRecord
 
            // Get a BluetoothSocket for a connection with the given BluetoothDevice 
            try { 
                if (secure) {
                    // tmp = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE); 
                    tmp = device.createRfcommSocketToServiceRecord(UUID_SPP);
                } else { 
                    tmp = device.createInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);
                } 
            } catch (IOException e) {
                Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
            } 
            mmSocket = tmp;
        } 
 
        public void run() { 
            Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType);
            setName("ConnectThread" + mSocketType);
 
            // Always cancel discovery because it will slow down a connection 
Full Snippet Info
6
CodeRank
Related Android BluetoothDevice Questions & Answers:
See Code Examples for Android BluetoothDevice Methods: