libGDX interfaces for native android code -
i use native android code in project of interface.
androidlauncher:
public int getnetworkstate() { int a; connectivitymanager connmanager = (connectivitymanager) getsystemservice(context.connectivity_service); networkinfo mwifi = connmanager.getnetworkinfo(connectivitymanager.type_wifi); if (mwifi.isconnected()) { a=1; } else { a=0; } return a; }
core:
public interface networkstate { public int getnetworkstate(); }
how can exact integer value in core project?
this solved doing following:
put platform specific code in class implements interface , have game class accept interface parameter in constructor.
so in core project, have game class;
public class gameinstance extends game { private networkstate networkstate; public gameinstance(networkstate networkstate) { this.networkstate = networkstate; } // override methods go below ... }
also, put networkstate interface in core:
public interface networkstate { public int getnetworkstate(); }
in android project put implementation;
public androidnetworkstate implements networkstate { public int getnetworkstate() { return 1; } }
and in androidlauncher create game object , pass interface implementation:
@override protected void oncreate (bundle savedinstancestate) { super.oncreate(savedinstancestate); androidapplicationconfiguration config = new androidapplicationconfiguration(); networkstate networkstate = new androidnetworkstate(); // or whatever called class initialize(new game(networkstate), config); }
and can call interface method in core project:
... int networkstateresult = this.networkstate.getnetworkstate(); ...
be sure provide implementations other platforms if support other platforms.
Comments
Post a Comment