Code example for BluetoothAdapter

Methods: listenUsingRfcommWithServiceRecord

0
 
        private BluetoothServerSocket getBluetoothServerSocket() throws IOException {
            BluetoothServerSocket tmp;
 
            if (VERSION.SDK_INT < VERSION_CODES.GINGERBREAD_MR1) {
                tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(SERVICE_NAME,
                        mServiceUuid);
                if (DBG) Log.d(TAG, "Using secure bluetooth server socket");
            } else { 
                try { 
                    // compatibility with pre SDK 10 devices 
                    Method listener = mBluetoothAdapter.getClass().getMethod(
                            "listenUsingInsecureRfcommWithServiceRecord", String.class, UUID.class);
                    tmp = (BluetoothServerSocket) listener.invoke(mBluetoothAdapter, SERVICE_NAME, mServiceUuid);
                    if (DBG) Log.d(TAG, "Using insecure bluetooth server socket");
                } catch (NoSuchMethodException e) {
                    Log.wtf(TAG, "listenUsingInsecureRfcommWithServiceRecord not found");
                    throw new IOException(e);
                } catch (InvocationTargetException e) {
                    Log.wtf(TAG,
                            "listenUsingInsecureRfcommWithServiceRecord not available on mBtAdapter");