Storing oauth token in the filesystem

In your common project, you should define an interface:

public interface IPlatform {
    public String getBaseDirectory();
}

And a singleton, where you can access the current platform:

public class PlatformService {

    public static IPlatform getPlatform() { /* .... */ }

    public static void initPlatform(IPlatform p) { /* ... */ }
}

In your main entry point (e.g. Android Application class, main() method on iOS), you instantiate the platform specific implementation of IPlatform and call PlatformService.initPlatform() with it.

Now you can access platform specific services / variables in a platform independent manner.

Best Regards,
Gergely

1 Like