我是新的Android编程和新的funf传感器框架。根据下面给出的例子,我是按照指定的时间间隔安排探头。但创建的sqlite数据库是空的,我不认为数据是根本收集的。任何想法请。funf调度和数据收集
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 is 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 is 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 {
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
}
}
}
}
}
我的strings.xml具有以下值预先指定
<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>
感谢。
更新:基于更新的onServiceConnected评论如下,但我仍然看不到数据库文件创建。我已完全卸载并重新安装了应用程序重新启动的手机。
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 is null");
pipeline = (BasicPipeline) manager.getRegisteredPipeline(PIPELINE_NAME);
manager.saveAndReload(PIPELINE_NAME, jsonobject);
manager.enablePipeline(PIPELINE_NAME);
}
else {
Log.e(TAG,"pipeline is NOT null");
Log.e(TAG,"Pipeline enabled? "+String.valueOf(pipeline.isEnabled()));
}
if (pipeline != null && !pipeline.isEnabled()){
Log.e(TAG,"pipeline is not null and is NOT enabled");
manager.enablePipeline(PIPELINE_NAME);
}
}
};
尝试启用管道后,您叫'saveAndReload'。除此之外,每次归档时都会将数据写入数据库文件。目前这是每60秒钟一次,所以我猜想在第一次保存管道后10秒内你并不需要手动存档。 – Blacklight 2014-11-05 11:55:18
此外,也许您需要在之后解除并重新安装应用程序,或者在'onServiceConnected'中启用管道(如果它不为null且尚未启用):if(pipeline!= null &&!pipeline.isEnabled( ))manager.enablePipeline(PIPELINE_NAME);'。 – Blacklight 2014-11-05 12:02:54
@Blacklight更新了代码,卸载并重新启动了手机,但仍然没有运气。 – Linus 2014-11-05 12:27:02