Rev*_*eva 5 android bluetooth android-4.4-kitkat
我需要在android中找到蓝牙mac地址.下面的代码
BluetoothAdapter.getDefaultAdapter().getAddress();
Run Code Online (Sandbox Code Playgroud)
它适用于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
Run Code Online (Sandbox Code Playgroud)
既
BluetoothManager ba=(BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
bmac=ba.getAdapter().getAddress();
Run Code Online (Sandbox Code Playgroud)
和
bmac=BluetoothAdapter.getDefaultAdapter().getAddress();
Run Code Online (Sandbox Code Playgroud)
在模拟器和genymotion模拟器为api级别19,kitkat
救命!
据我所知,标准模拟器和genymotion都默认不支持蓝牙(有传言说genymotion将支持蓝牙)。您可以在基于 VirtualBox 的模拟器上启用蓝牙,这在此处进行了描述,但我没有尝试过。
从静态方法检索 BluetoothAdapterBluetoothAdapter.getDefaultAdapter()对于所有平台都是正确的。BluetoothManager 可从 API 18 获取。
| 归档时间: |
|
| 查看次数: |
9845 次 |
| 最近记录: |