Force an Android application to use an old API for one section of code

618 views Asked by At

For several days now, I have been trying to work out a way of using a previous Android API's implementation of a method in an app that has been built with a newer API.

Specifically, I am using startBluetoothSco() to initiate a virtual call over a Bluetooth SCO channel. In API 17, this works perfectly, however, in API 18 onwards startBluetoothSco() opens a raw SCO channel instead of a virtual call (as stated in the developer docs: http://developer.android.com/reference/android/media/AudioManager.html#startBluetoothSco() ). The accessory I am working with does not do anything with the raw SCO channel.

In this scenario, it is not an option for me to build the app with API 17 as it is likely that other developers will require features of later APIs in the near future.

I did think that I may be able to wrap the Bluetooth code in a library project, build this with API 17 then integrate it into the main application, which would then be built at API 18. Unfortunately, this didn't work; it appears the OS sees the fact that startBluetoothSco() is being called from an app which was built with API 18, and therefore uses the API 18 implementation of the method.

If anyone could please suggest any way by which I can force an API 18 application to use the API 17 implementation, I would be very grateful.

Thanks

1

There are 1 answers

4
CommonsWare On

In this scenario, it is not an option for me to build the app with API 17 as it is likely that other developers will require features of later APIs in the near future.

What you build with does not matter. What you are running on is what matters. If you are saying that, starting with API Level 18, startBluetoothSco() does not work with your hardware, then Android 4.3+ devices will not work with your hardware.

Unfortunately, this didn't work; it appears the OS sees the fact that startBluetoothSco() is being called from an app which was built with API 18, and therefore uses the API 18 implementation of the method.

It uses "the API 18 implementation of the method" because that is all that it has, if it is an Android 4.3 device.

If anyone could please suggest any way by which I can force an API 18 application to use the API 17 implementation, I would be very grateful.

Install a ROM mod based on Android 4.2 on the device.