android:name="android.permission.bluetooth_admin" />
android:name="android.permission.bluetooth" />
android:name="android.permission.access_coarse_location" />
bluetoothadapter mbluetoothadapter =bluetoothadapter.getdefaultadapter();
開啟關閉藍芽
第一種開啟藍芽的方法
bluetoothadapter.enable();//這個方法沒有提示視窗,直接開啟藍芽
第二種開啟藍芽的方法
intent request = new intent(bluetoothadapter.action_request_enable);
startactivityforresult(request,100);
這種開啟方法有互動介面,使用者可以選擇是否開啟藍芽
關閉藍芽
bluetoothadapter.disable();
if (mbluetoothadapter != null && mbluetoothadapter.isenabled())
mbluetoothadapter.startdiscovery();
}
/**
* 註冊藍芽廣播接收者
*/private
void
registbluetoothbroadcastreceiver()
bluetoothdevice.action_found:每當掃瞄到藍芽裝置時,就會走這裡
case bluetoothdevice.action_found:
//device = intent.getparcelableextra(bluetoothdevice.extra_device);
int deviceclasstype = device.getbluetoothclass().getdeviceclass();
//找到指定的藍芽裝置
if ((deviceclasstype == bluetoothclass.device
.audio_video_wearable_headset
|| deviceclasstype == bluetoothclass.device
.audio_video_headphones)
&& device.getname().equals(pubutils.devicename)) else
if (dialog_match != null && dialog_match.isshowing())
//break
;
bluetoothadapter.action_state_changed:藍芽狀態:藍芽開啟關閉時會走這裡
case bluetoothadapter.action_state_changed:
//int state = intent.getintextra(bluetoothadapter.extra_state, -1);
switch (state)
bluetoothdevice.action_bond_state_changed:裝置配對時各個狀態
case bluetoothdevice.action_bond_state_changed://配對狀態
//int bondstate = intent.getintextra(bluetoothdevice.extra_bond_state, bluetoothdevice.bond_none);
device = intent.getparcelableextra(bluetoothdevice.extra_device);
switch (bondstate)
/**
* 開始配對
*/private
void
startmarth()
set
localset = bluetoothadapter.getbondeddevices();
檢視手機有沒有連線藍芽耳機
/**
* 檢視手機有沒有已經連線的藍芽
*@return
*/public
boolean
blootoothconnected() else
}
Android藍芽開發
藍芽開發,也就那麼幾個操作,開啟 搜尋 配對 連線 通訊。其他的東西都是建立在這麼幾個之上。下面就來說說這幾個基本操作。使用前,首先加入藍芽的兩個基本許可權。然後他們基本圍繞這麼幾個類來用。這些類是什麼,慢慢來說。bluetoothadapter bluetoothadapter bluetooth...
Android 藍芽基礎
藍芽發展至今經歷了8個版本的更新。1.1 1.2 2.0 2.1 3.0 4.0 4.1 4.2。那麼在1.x 3.0之間的我們稱之為傳統藍芽 4.x開始的藍芽我們稱之為低功耗藍芽也就是藍芽ble,當然4.x版本的藍芽也是向下相容的。android手機必須系統版本4.3及以上才支援ble api。還...
Android藍芽操作
藍芽是一種支援裝置短距離傳輸資料的無線技術。android在2.0以後提供了這方面的支援。從查詢藍芽裝置到能夠相互通訊要經過幾個基本步驟 本機做為伺服器 1.設定許可權 在manifest中配置 uses permission android name android.permission.blue...