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

熱點內容
解壓小熊手機殼 瀏覽:342
成都市區建成面積演算法 瀏覽:658
智能家居單片機 瀏覽:95
買男裝用什麼app好 瀏覽:853
文件夾合並了怎麼拆開 瀏覽:257
波段副圖源碼無未來函數 瀏覽:86
livecn伺服器地址 瀏覽:257
程序員這個工作真的很吃香嗎 瀏覽:844
程序員和數學分析師待遇 瀏覽:678
壓縮氣彈簧怎麼拆 瀏覽:321
華為公有雲伺服器添加虛擬ip 瀏覽:209
程序員和運營哪個累 瀏覽:24
抖音安卓信息提示音怎麼設置 瀏覽:454
光速虛擬機的共享文件夾 瀏覽:248
程序員培訓機構發的朋友圈真實性 瀏覽:744
天乾地支簡單演算法 瀏覽:299
下載個壓縮文件 瀏覽:300
普通人電腦關機vs程序員關機 瀏覽:630
米酷建站源碼 瀏覽:115
氫氣app怎麼搜搭配 瀏覽:619