第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Android示例藍(lán)牙代碼可通過藍(lán)牙發(fā)送簡單的字符串

Android示例藍(lán)牙代碼可通過藍(lán)牙發(fā)送簡單的字符串

暮色呼如 2019-09-21 11:23:47
我想通過藍(lán)牙將一個(gè)簡單的字符串?dāng)?shù)據(jù)(例如“ a”)從android設(shè)備發(fā)送到其他設(shè)備。我在android sdk中查看了示例藍(lán)牙代碼,但這對我來說太復(fù)雜了。按下按鈕時(shí),我無法理解如何僅發(fā)送特定數(shù)據(jù)。我怎么解決這個(gè)問題?
查看完整描述

2 回答

?
牧羊人nacy

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊

private OutputStream outputStream;

private InputStream inStream;


private void init() throws IOException {

    BluetoothAdapter blueAdapter = BluetoothAdapter.getDefaultAdapter();

    if (blueAdapter != null) {

        if (blueAdapter.isEnabled()) {

            Set<BluetoothDevice> bondedDevices = blueAdapter.getBondedDevices();


            if(bondedDevices.size() > 0) {

                Object[] devices = (Object []) bondedDevices.toArray();

                BluetoothDevice device = (BluetoothDevice) devices[position];

                ParcelUuid[] uuids = device.getUuids();

                BluetoothSocket socket = device.createRfcommSocketToServiceRecord(uuids[0].getUuid());

                socket.connect();

                outputStream = socket.getOutputStream();

                inStream = socket.getInputStream();

            }


            Log.e("error", "No appropriate paired devices.");

        } else {

            Log.e("error", "Bluetooth is disabled.");

        }

    }

}


public void write(String s) throws IOException {

    outputStream.write(s.getBytes());

}


public void run() {

    final int BUFFER_SIZE = 1024;

    byte[] buffer = new byte[BUFFER_SIZE];

    int bytes = 0;

    int b = BUFFER_SIZE;


    while (true) {

        try {

            bytes = inStream.read(buffer, bytes, BUFFER_SIZE - bytes);

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

}


查看完整回答
反對 回復(fù) 2019-09-21
  • 2 回答
  • 0 關(guān)注
  • 1037 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號