5

解答如何在安卓模拟器中使用蓝牙?

我试图启用禁用蓝牙设备。出于这个原因,我写了下面的代码,但它给出了错误,它也在下面。

if ( bluetoothAdmin == null ) {

    return ;
}
if ( bluetooth . isEnabled()){
    bluetooth . disable ();
}
else {
    bluetooth . enable();
}

在创建

BLuetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter() ;

在清单中

<uses-permission
    android:name="android.permission.BLUETOOTH" 
/>
<uses-permission
    android:name="android.permission.BLUETOOTH_ADMIN" 
/>

错误 :

01-23 07:18:53.167: E/BluetoothAdapter(883): Bluetooth binder is null

堆栈的一半:

01-23 07:36:55.624: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
01-23 07:37:16.954: E/ActivityThread(642): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d51230 that was originally bound here
01-23 07:37:16.954: E/ActivityThread(642): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d51230 that was originally bound here
01-23 07:37:16.954: E/ActivityThread(642):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
01-23 07:37:16.954: E/ActivityThread(642):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
01-23 07:37:16.954: E/ActivityThread(642):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
01-23 07:37:16.954: E/ActivityThread(642):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
01-23 07:37:16.954: E/ActivityThread(642):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
01-23 07:37:16.954: E/ActivityThread(642):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
01-23 07:37:16.954: E/ActivityThread(642):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
01-23 07:37:16.954: E/ActivityThread(642):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:11    6)
01-23 07:37:16.954: E/ActivityThread(642):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
01-23 07:37:16.954: E/ActivityThread(642):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
01-23 07:37:16.954: E/ActivityThread(642):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
01-23 07:37:16.954: E/ActivityThread(642):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
01-23 07:37:16.954: E/ActivityThread(642):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-23 07:37:16.954: E/ActivityThread(642):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-23 07:37:16.954: E/ActivityThread(642):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-23 07:37:16.954: E/ActivityThread(642):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-23 07:37:16.954: E/ActivityThread(642):  at java.lang.Thread.run(Thread.java:856)
01-23 07:37:16.964: E/StrictMode(642): null
01-23 07:37:16.964: E/StrictMode(642): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d51230 that was originally bound here

我在安卓模拟器上测试

4

3 回答 3

9

The emulator doesnt support bluetooth as mentioned in the sdk's docs. You have to check this in real device..

And you got error Bluetooth binder is null. it means emulator does not have bluetooth capability.

于 2014-01-09T07:29:14.590 回答
3

Android 模拟器不支持蓝牙。这就是您收到错误的原因。您可以使用连接到计算机/笔记本电脑的智能手机来测试您的应用程序。

于 2017-04-04T07:21:11.210 回答
0

由于您的帖子中缺少信息,我假设您的课程扩展了服务,因为这一行:

android.app.ServiceConnectionLeaked: Service

在您的onStop方法中,请解除服务与您的活动的绑定。

unbindService(whatever_your_service_object_are); 

如果这是完全错误的答案,请发布更多代码,以及类声明等。

于 2013-01-23T08:13:57.890 回答