導航:首頁 > 軟體資訊 > APP藍牙怎麼設置自動重連

APP藍牙怎麼設置自動重連

發布時間:2023-12-20 19:54:22

A. 如何實現android藍牙自動配對連接

android藍牙自動配對連接的具體代碼如下:
1. 獲取藍牙適配器BluetoothAdapter blueadapter=BluetoothAdapter.getDefaultAdapter();
如果BluetoothAdapter 為null,說明android手機沒有藍牙模塊。
2. 判斷藍牙模塊是否開啟,blueadapter.isEnabled() true表示已經開啟,false表示藍牙並沒啟用。
3. 啟動配置藍牙可見模式,即進入可配對模式Intent in=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
in.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 200);
startActivity(in); ,200就表示200秒。
4. 獲取藍牙適配器中已經配對的設備Set device=blueadapter.getBondedDevices();
當然,還需要在androidManifest.xml中聲明藍牙的許可權5.自動配對設置Pin值

static public boolean autoBond(Class btClass, BluetoothDevice device, String strPin)
throws Exception {
Method autoBondMethod = btClass.getMethod("setPin", new Class[] { byte[].class });
Boolean result = (Boolean) autoBondMethod
.invoke(device, new Object[] { strPin.getBytes() });
return result;
}

6.開始配對請求
static public boolean createBond(Class btClass, BluetoothDevice device) throws Exception {
Method createBondMethod = btClass.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
return returnValue.booleanValue();
}

閱讀全文

與APP藍牙怎麼設置自動重連相關的資料

熱點內容
apk文件反編譯後安裝包損壞 瀏覽:796
app圖標分別是什麼 瀏覽:349
linux全選命令 瀏覽:360
怎麼用華碩app 瀏覽:945
小明台灣通道加密 瀏覽:358
apriori演算法的java 瀏覽:697
jscanvas壓縮圖片 瀏覽:375
單片機與汽車單片機有何不同 瀏覽:955
獸醫雲平台伺服器 瀏覽:308
php循環字母 瀏覽:650
盛達是什麼APP 瀏覽:210
android計算屏幕高度 瀏覽:664
自己做紅包解壓球 瀏覽:486
pdf很貴嗎 瀏覽:506
如何搶購騰訊雲伺服器 瀏覽:400
電子書app源碼 瀏覽:881
程序員在上班的時候 瀏覽:406
游戲壓縮文件夾怎麼刪除 瀏覽:431
百度新聞app是什麼 瀏覽:900
自動化對初級編程的影響 瀏覽:119