導航:首頁 > 軟體資訊 > 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藍牙怎麼設置自動重連相關的資料

熱點內容
做一個app或者網頁用什麼編程 瀏覽:766
一體機伺服器運行失敗怎麼辦 瀏覽:927
longjava比較大小 瀏覽:521
clojure編程pdf 瀏覽:11
一年級數學圈一圈的演算法 瀏覽:100
完整的python 瀏覽:31
c51單片機數字鍾 瀏覽:912
apk文件反編譯後安裝包損壞 瀏覽:806
app圖標分別是什麼 瀏覽:358
linux全選命令 瀏覽:365
怎麼用華碩app 瀏覽:954
小明台灣通道加密 瀏覽:365
apriori演算法的java 瀏覽:706
jscanvas壓縮圖片 瀏覽:382
單片機與汽車單片機有何不同 瀏覽:963
獸醫雲平台伺服器 瀏覽:315
php循環字母 瀏覽:657
盛達是什麼APP 瀏覽:217
android計算屏幕高度 瀏覽:671
自己做紅包解壓球 瀏覽:493