Get IBluetooth instance


/ Published in: Java
Save to your folder(s)

You need to create a new package android.bluetooth in your project, and add the files: IBluetooth.aidl y IBluetoothCallback.aidl from the android source code


Copy this code and paste it in your HTML
  1. private IBluetooth getIBluetooth() {
  2.  
  3. IBluetooth ibt = null;
  4.  
  5. try {
  6.  
  7. Class c2 = Class.forName("android.os.ServiceManager");
  8.  
  9. Method m2 = c2.getDeclaredMethod("getService",String.class);
  10. IBinder b = (IBinder) m2.invoke(null, "bluetooth");
  11.  
  12. Class c3 = Class.forName("android.bluetooth.IBluetooth");
  13.  
  14. Class[] s2 = c3.getDeclaredClasses();
  15.  
  16. Class c = s2[0];
  17. Method m = c.getDeclaredMethod("asInterface",IBinder.class);
  18. m.setAccessible(true);
  19. ibt = (IBluetooth) m.invoke(null, b);
  20.  
  21.  
  22. } catch (Exception e) {
  23. Log.e(TAG, "Erroraco!!! " + e.getMessage());
  24. }
  25.  
  26. return ibt;
  27. }
  28.  
  29.  
  30.  
  31.  
  32. /************************ IBluetooth.aidl ************************/
  33.  
  34. package android.bluetooth;
  35.  
  36. import android.bluetooth.IBluetoothCallback;
  37. import android.os.ParcelUuid;
  38.  
  39. /**
  40.  * System private API for talking with the Bluetooth service.
  41.  *
  42.  * {@hide}
  43.  */
  44. interface IBluetooth
  45. {
  46. boolean isEnabled();
  47. int getBluetoothState();
  48. boolean enable();
  49. boolean disable(boolean persistSetting);
  50.  
  51. String getAddress();
  52. String getName();
  53. boolean setName(in String name);
  54.  
  55. int getScanMode();
  56. boolean setScanMode(int mode, int duration);
  57.  
  58. int getDiscoverableTimeout();
  59. boolean setDiscoverableTimeout(int timeout);
  60.  
  61. boolean startDiscovery();
  62. boolean cancelDiscovery();
  63. boolean isDiscovering();
  64.  
  65. boolean createBond(in String address);
  66. boolean cancelBondProcess(in String address);
  67. boolean removeBond(in String address);
  68. String[] listBonds();
  69. int getBondState(in String address);
  70.  
  71. String getRemoteName(in String address);
  72. int getRemoteClass(in String address);
  73. ParcelUuid[] getRemoteUuids(in String address);
  74. boolean fetchRemoteUuids(in String address, in ParcelUuid uuid, in IBluetoothCallback callback);
  75. int getRemoteServiceChannel(in String address, in ParcelUuid uuid);
  76.  
  77. boolean setPin(in String address, in byte[] pin);
  78. boolean setPasskey(in String address, int passkey);
  79. boolean setPairingConfirmation(in String address, boolean confirm);
  80. boolean cancelPairingUserInput(in String address);
  81.  
  82. boolean setTrust(in String address, in boolean value);
  83. boolean getTrustState(in String address);
  84.  
  85. int addRfcommServiceRecord(in String serviceName, in ParcelUuid uuid, int channel, IBinder b);
  86. void removeServiceRecord(int handle);
  87. }
  88.  
  89.  
  90.  
  91. /************************ IBluetoothCallback.aidl ************************/
  92.  
  93. package android.bluetooth;
  94.  
  95. /**
  96.  * System private API for Bluetooth service callbacks.
  97.  *
  98.  * {@hide}
  99.  */
  100. interface IBluetoothCallback
  101. {
  102. void onRfcommChannelFound(int channel);
  103. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.