How do I use AIDL or talk to Android Services from codenameone? -
i building android pos application using codenameone. want use cmsoft bt-printer sdk here http://www.cm-soft.com/androidprintersdk.htm. uses aidl interface. how access codenameone project?
1)create in project regular interface extends nativeinterface communicate printer service.
2) interface printerinterface extends nativeinterface{
public void bindservice(); public void startscan(); public void stopscan(); }
3)right click on interface , select "generate native access" - create implementation files under native directory in project.
4)under native/android dir printerinterfaceimpl class make sure issupported() method returns true , implement android code in class.
use androidnativeutil.getactivity() gain access activity. example:
androidnativeutil.getactivity().registerreceiver(mreceiver, new intentfilter(receiver));
androidnativeutil.getactivity().unregisterreceiver(mreceiver);
5)in impl class can bind receiver:
final class scannerreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { string data = null; if (intent.getaction().equals(receiver)) { data = intent.getstringextra(data); } if (data != null) { string msg; if (data.startswith("s:")) { msg = data.substring(data.indexof(':', 2) + 1); } if (data.startswith("d:")) { msg = data.substring(data.indexof(':', 2) + 1); } } } } private final scannerreceiver mreceiver = new scannerreceiver(); private final intent mservice = new intent(service);
Comments
Post a Comment