Android中藍芽的簡單使用

2021-09-01 09:28:40 字數 973 閱讀 8425

1、

宣告藍芽許可權:

2、 關鍵**:

獲取到藍芽介面卡

bluetoothadapter bluetoothadapter= bluetoothadapter.getdefaultadapter();

bluetoothadapter.isenabled(); // 判斷藍芽是否開啟

bluetoothadapter.enable();// 開啟藍芽

bluetoothadapter.disable();// 關閉藍芽

bluetoothadapter.startdiscovery();// 開始掃瞄

3、動態註冊乙個廣播來接收掃瞄到的藍芽裝置

private broadcastreceiver bluetoothreceiver = new broadcastreceiver() }};

// 動態註冊廣播

intentfilter filter = new intentfilter();

filter.addaction(bluetoothdevice.action_found);

registerreceiver(bluetoothreceiver, filter);

//這裡是使用recycleview進行顯示的

public void refresh(bluetoothdevice device)

}4、連線藍芽

private outputstream outputstream;

/***   藍芽的連線也是耗時操作,與訪問網路差不多,所以需要建立子執行緒進行執行

*/private void connect (final bluetoothdevice device) catch (ioexception e)

}}.start();

}

個人淺見,有錯誤請幫忙指出,謝謝!

Android中的Intent簡單使用

如下 uri uri uri.parse intent it new intent intent.action view,uri startactivity it 顯示地圖 如下 uri uri uri.parse geo 38.899533,77.036476 intent it new inte...

Android藍芽BLE(一) 使用介紹

一 基本ble概念介紹 藍芽ble,主要以中心裝置和周邊裝置作為區分,分別對應ble裝置的主機 從機,其主要區別是,從機可以發起廣播,而主機能掃瞄廣播,並主機連線ble藍芽從機。目前在android 平台上,主機api從4.3以上已經支援,而從機api需要5.0以上的系統才能使用。二 ble 協議介...

Android 的藍芽簡介

24 june 2015 on android 本文主要是翻譯了 google 的官方文件。android 提供預設的藍芽協議棧是 bluedroid,分為兩層 藍芽嵌入式系統 bte 和藍芽應用層 bta bte 層主要實現藍芽的核心功能,bta 層則主要負責和 anroid 框架通訊。andro...