How to use specific iOS and Android hardware?

I am starting in MOE development and getting in doubt how to use bluetooth hardware. I can do a common module with bluetooth or I have to do separate modules (one module with bluetooth android and another to bluetooth ios)?

Thanks in advanced.

Hi,

MOE provides a thin wrapper over the Objective-C bluetooth API that is a 1 to 1 match of the iOS API. The usual pattern to handle the access to different HW and platform SW features in a cross platform app is to create a common interface, like this (just an example, not an actual API suggestion):


public interface BluetoothService {

List<BluetoothDevice> findDevices();

BluetoothConnection connect(BluetoothDevice b);

// ...
}

Then you need to create separate implementations for iOS and Android using the respective device specific APIs.

It would be great to have generic cross platform APIs available for the common HW and SW features, but it was not implemented yet.

If you are building a game, some of these abstractions are already present in libgdx or one of its modules.

Best Regards,
Gergely

Thanks for reply.

Do you know some example or tutorial? It is not need to be a bluetooth example, but a example that contains Android and iOS specific APIs.

Thanks in advanced again.

Hi,

It is impossible to make a best multiplatform API.
Each project has its own needs, and the best API would be to implement what you need and do not implement more. Try to implement on both platforms (IOs, Android) and then introduce a common interface so that planform impl will be behind.
And this will be the API for your needs.

Hello.

Sorry for my delay answer. Have you any example for this?

You can check out my answer to this other topic:

It describes how to handle filesystem folders in a platform independent manner, but it can be generalised to any service.

1 Like