2

My project needs the following classes to build:

  • BluetoothA2dpSink

  • BluetoothAvrcpController

According to this & this, the classes are part of the Android SDK but are disabled by default because these bluetooth profiles are not used on most phones. We have a custom ROM for our device so these bluetooth profiles will work just fine with our device.

The answers in the questions above say that you can modify the SDK to include the missing classes so Android Studio will recognize them and build. So my questions are:

  1. How can I add these classes to the SDK even though they are already there? (C:\Users\USERNAME\AppData\Local\Android\sdk\sources\android-23\android\bluetooth) is their location.
  2. How do I actually modify the SDK and recompile it? I found this question but it is from several years ago and points to instructions that are several years old as well.
Daniel
  • 2,355
  • 9
  • 23
  • 30

2 Answers2

1

It seems that the classes are not public and you might have to access them via reflection (on your own risk). Also, the documentation for BluetoothA2dpSink indicates:

BluetoothA2dpSink is a proxy object for controlling the Bluetooth A2DP Sink * Service via IPC. Use {@link BluetoothAdapter#getProfileProxy} to get * the BluetoothA2dpSink proxy object.

Roberto Betancourt
  • 2,375
  • 3
  • 27
  • 35
1

Although my question was very specific, after much research, I figured out that I was trying to use what is commonly referred to as hidden APIs. There are a few solutions for this. I am not familiar with reflection so I did not use it. Here is what I did instead:

  1. Obtain the classes that you're missing by pulling the framework.jar file from a device. So plug in a device and use the following adb command:

    adb pull /system/framework/framework.jar
    
  2. Rename the framework.jar file to framework.zip so you can open it and extract it. Extract the dex file(s) from the zipped file.
  3. Use dex2jar to turn your dex files into JAR files and then extract the class files you need from the generated JAR files. You now have the classes that you're missing so the next step is to put then in your actual SDK.
  4. Go to [Your SDK location]\sdk\platforms\[the SDK version you need to compile against]\ and rename the android.jar file to android.zip and extract it.
  5. Copy the extracted classes you need from the JAR files that dex2jar generated to the extracted android folder.
  6. Zip the android folder back up and name it android.jar.

Further references:

This question has general advice on the general idea of using hidden APIs.

Daniel
  • 2,355
  • 9
  • 23
  • 30