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

熱點內容
國外代理伺服器地址伺服器埠密碼 瀏覽:751
phpthrownew 瀏覽:676
java從入門到精通pdf百度雲 瀏覽:54
linuxhdf5安裝 瀏覽:468
java繼承編程練習題 瀏覽:651
雲記app怎麼寫字視頻 瀏覽:597
如何進入我的世界臟小豆的伺服器 瀏覽:41
哪裡找到轉轉app 瀏覽:579
蘋果二次app怎麼注冊 瀏覽:586
國際服體驗服伺服器為什麼爆滿 瀏覽:113
微信商城模板源碼 瀏覽:435
網頁的源碼怎麼讀取 瀏覽:401
ubuntu命令打開軟體 瀏覽:760
如何實現對講頻道加密 瀏覽:350
福州8000的程序員去深圳多少 瀏覽:644
保存加密是什麼意思 瀏覽:42
安裝不了軟體顯示加密目錄 瀏覽:910
php53下載64位 瀏覽:99
osip源碼結構 瀏覽:957
如何刪除加密網站 瀏覽:716