android - funf scheduling and data collection -
android - funf scheduling and data collection -
i new android programming , new funf sensor framework. based on illustration give below take on scheduling probe @ specified intervals. sqlite database created empty , dont think info collected @ all. ideas please.
public class mainactivity extends activity { private static final string tag = "app"; protected static final string pipeline_name = "default_pipeline"; private funfmanager manager; private pipeline pipeline; private handler handler; private serviceconnection conn = new serviceconnection() { @override public void onservicedisconnected(componentname name) { log.e(tag,"onservicedisconnected"); manager = null; } @override public void onserviceconnected(componentname name, ibinder service) { log.e(tag,"onserviceconnected"); manager = ((funfmanager.localbinder)service).getmanager(); pipeline = (basicpipeline) manager.getregisteredpipeline(pipeline_name); jsonobject jsonobject = (new jsonparser()).parse(getstring(r.string.default_pipeline)).getasjsonobject(); if (pipeline == null){ log.e(tag,"pipeling null"); manager.enablepipeline(pipeline_name); boolean flag = manager.saveandreload(pipeline_name, jsonobject); log.e(tag,string.valueof(flag)); if (flag){ pipeline = manager.getregisteredpipeline(pipeline_name); handler.postdelayed(new runnable() { @override public void run() { // todo auto-generated method stub log.e(tag,"will archive now"); pipeline.onrun("archive",null); } }, 10000l); } } else { log.e(tag,"pipeling not null"); } } }; @override protected void oncreate(bundle savedinstancestate) { log.e(tag,"oncreate"); super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); handler = new handler(); bindservice(new intent(this, funfmanager.class), conn, bind_auto_create); waitforserviceconnection(3000); } @override protected void ondestroy() { log.e(tag,"ondestroy"); super.ondestroy(); unbindservice(conn); } public void waitforserviceconnection(long millistowait) { long time = system.currenttimemillis(); while (system.currenttimemillis() < time + millistowait) { if (manager != null) { break; } else { seek { thread.sleep(100); } grab (interruptedexception e) { } } } } }
my strings.xml has below value specified
<string name="default_pipeline">{ "name": "example", "version":1, "archive": { "@schedule": {"interval": 60} }, "upload": { "url": \"http://www.samplewebsite.com/uploadurl\", "@schedule": {"interval": 60} }, "update": { "url": \"http://www.samplewebsite.com/funfconfig\", "@schedule": {"interval": 60} }, "data": [ {"@type": "edu.mit.media.funf.probe.builtin.locationprobe", "@schedule": {"interval": 5} } ] }</string>
thanks in advance.
update: based on comment updated onserviceconnected below, still dont see database files created. have uninstalled , reinstalled app restarted phone.
private serviceconnection conn = new serviceconnection() { @override public void onservicedisconnected(componentname name) { log.e(tag,"onservicedisconnected"); manager = null; } @override public void onserviceconnected(componentname name, ibinder service) { log.e(tag,"onserviceconnected"); manager = ((funfmanager.localbinder)service).getmanager(); pipeline = (basicpipeline) manager.getregisteredpipeline(pipeline_name); jsonobject jsonobject = (new jsonparser()).parse(getstring(r.string.default_pipeline)).getasjsonobject(); if (pipeline == null){ log.e(tag,"pipeline null"); pipeline = (basicpipeline) manager.getregisteredpipeline(pipeline_name); manager.saveandreload(pipeline_name, jsonobject); manager.enablepipeline(pipeline_name); } else { log.e(tag,"pipeline not null"); log.e(tag,"pipeline enabled? "+string.valueof(pipeline.isenabled())); } if (pipeline != null && !pipeline.isenabled()){ log.e(tag,"pipeline not null , not enabled"); manager.enablepipeline(pipeline_name); } } };
the name of pipeline not "default_pipeline", that's resource name. it's "example" according config, seek this:
protected static final string pipeline_name = "example";
other config looks fine. little optimization still possible:
private serviceconnection conn = new serviceconnection() { @override public void onservicedisconnected(componentname name) { log.i(tag,"onservicedisconnected"); manager = null; } @override public void onserviceconnected(componentname name, ibinder service) { log.i(tag,"onserviceconnected"); manager = ((funfmanager.localbinder)service).getmanager(); pipeline = (basicpipeline) manager.getregisteredpipeline(pipeline_name); if (pipeline == null){ log.i(tag,"pipeline null"); jsonobject jsonobject = (new jsonparser()).parse(getstring(r.string.default_pipeline)).getasjsonobject(); manager.saveandreload(pipeline_name, jsonobject); manager.enablepipeline(pipeline_name); pipeline = (basicpipeline) manager.getregisteredpipeline(pipeline_name); } if (pipeline != null && !pipeline.isenabled()){ log.e(tag,"pipeline not null , not enabled"); manager.enablepipeline(pipeline_name); } } };
you seek simplify configuration bit narrow down:
{ "name": "example", "version":1, "archive": { "@schedule": {"interval": 60} }, "data": [ {"@type": "edu.mit.media.funf.probe.builtin.locationprobe", "@schedule": {"interval": 5} } ] }
android scheduled-tasks android-sensors
Comments
Post a Comment