[英]How to find bluetooth mac address programmatically in Android api level 19
我需要在android中找到藍牙mac地址。 下面的代碼
BluetoothAdapter.getDefaultAdapter().getAddress();
它適用於18級及以下的api。
如何找到與api級別19相同的?
“要獲得代表本地藍牙適配器的BluetoothAdapter,在JELLY_BEAN_MR1及以下版本上運行時,請調用靜態getDefaultAdapter()方法;在JELLY_BEAN_MR2及更高版本上運行時,請使用來自http:// developer的 BLUETOOTH_SERVICE”通過getSystemService(String)檢索它。 android.com/reference/android/bluetooth/BluetoothAdapter.html
我收到以下錯誤:
bluetooth binder is null
既
BluetoothManager ba=(BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
bmac=ba.getAdapter().getAddress();
和
bmac=BluetoothAdapter.getDefaultAdapter().getAddress();
在模擬器和genymotion模擬器為api級別19,kitkat
救命!
據我所知,默認情況下,標准模擬器和genymotion都不支持藍牙(有傳言稱genymotion支持藍牙)。 您可以在此處描述的基於VirtualBox的仿真器上啟用藍牙,但我沒有嘗試過。
從靜態方法檢索BluetoothAdapter BluetoothAdapter.getDefaultAdapter()
對於所有平台都是正確的。 Bluetooth 18可從API 18獲得。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.