5

ANSWER:How to use Bluetooth in Android emulator?

I have tried to enable disable bluetooth device. For this reason, I have wrote below code but it gives the error, which is also at below.

if ( bluetoothAdmin == null ) {

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

in on create

BLuetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter() ;

in manisfest

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

error :

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

half of the stack:

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

I am testing on the Android emulator

Community
  • 1
  • 1
John poer
  • 53
  • 1
  • 1
  • 6
  • Where does this error comes from ? Do you have a full stack showning the line ? Did you read the full javadoc for enable() ? (which is very complete with some very important advices) – Orabîg Jan 23 '13 at 07:34
  • I'm maybe blind, but I can't see the error message in the stack... The link between this stack and you issue is not even clear... – Orabîg Jan 23 '13 at 07:46
  • @Orabîg sometmes the only error on the stack is first one. Most of the time stack gives the latter errors. Is the code correct ? – John poer Jan 23 '13 at 07:48
  • @Orabîg what is the meaning of the first error? – John poer Jan 23 '13 at 08:01
  • @Orabîg if it is possible, can I run on your ADT ? – John poer Jan 23 '13 at 08:11

3 Answers3

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.

sagar.android
  • 1,860
  • 17
  • 17
4

Android Emulator does not support Bluetooth. That is why you are getting an error. You can use a Smartphone connected to your Computer/Laptop to test your app.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Jeff Salim
  • 41
  • 5
0

By the lack of information in your post I assume that your class extends Service, due to this line:

android.app.ServiceConnectionLeaked: Service

In your onStop method, please unbind the Service from your activity.

unbindService(whatever_your_service_object_are); 

If this is answer is totaly wrong, please post some more code, with the class declaration and so on.

Tobias Moe Thorstensen
  • 8,861
  • 16
  • 75
  • 143
  • `public class BluetoothAdmin extends Activity implements OnCheckedChangeListener`. If you want specific code, I will post – John poer Jan 23 '13 at 08:26
  • 1
    Please post all the code regarding this issue, it will help us alot. And please dont post "Half" of the LogCat. – Tobias Moe Thorstensen Jan 23 '13 at 08:37
  • sorry for the my idiot. I recently learned Android Emulator does not support the bluetooth. I have added at the top of the question. – John poer Jan 23 '13 at 08:48