安卓&;Felix OSGI-与Android GUI的通信?
我们正在Android(2.1)上成功运行ApacheFelix4.0.3,并且可以在运行时部署/删除捆绑包。对于OSGI捆绑包之间的依赖关系管理,我们使用Felix DependenyManager 现在我们想将运行OSGI捆绑包的数据发送到Android GUI并显示它安卓&;Felix OSGI-与Android GUI的通信?,android,osgi,apache-felix,Android,Osgi,Apache Felix,我们正在Android(2.1)上成功运行ApacheFelix4.0.3,并且可以在运行时部署/删除捆绑包。对于OSGI捆绑包之间的依赖关系管理,我们使用Felix DependenyManager 现在我们想将运行OSGI捆绑包的数据发送到Android GUI并显示它 我们怎样才能完成这项任务?我们可以使用某种回调吗?假设“发送数据”是指与捆绑包提供的服务进行交互,这没有什么特别之处:只要确保您持有您的Felix实例提供给您的BundleContext实例,并使用它来请求服务。绑定数据的方
我们怎样才能完成这项任务?我们可以使用某种回调吗?假设“发送数据”是指与捆绑包提供的服务进行交互,这没有什么特别之处:只要确保您持有您的
Felix
实例提供给您的BundleContext
实例,并使用它来请求服务。绑定数据的方式完全取决于您,就像在任何其他Java项目中一样
只是显示数据
作为一个相当做作的例子,你可以做如下的事情
Map<String, Object> config = new HashMap<String, Object>();
/// make settings here, including providing the bundles to start
Felix felix = new Felix(config);
felix.start();
BundleContext context = felix.getBundleContext();
// now get some service! Remember to do nullchecks.
ServiceReference<PackageAdmin> ref = context.getServiceReference(PackageAdmin.class);
PackageAdmin admin = context.getService(ref);
ExportedPackage[] exportedPackages = admin.getExportedPackages(felix);
// use the result to update your UI
TextView field = (TextView) findViewById(R.id.textfield);
field.setText(exportedPackages[0].getName());
您有一些服务定期调用所有在当前时间实现此接口的服务。现在,您可以创建一个TextField
,该字段在每次调用此方法时自动更新。大概
public class ClockTextField extends TextView implements ClockListener {
public ClockTextField(Context context) {
super(context);
}
public void timeChanged(String newTime) {
setText(newTime);
}
public void register(BundleContext bundleContext) {
// remember to hold on to the service registration, so you can pull the service later.
// Better yet, think about using a dependency management tool.
bundleContext.registerService(ClockListener.class, this, null);
}
}
你查过如何做的信息了吗?是的,我查过了,但没有关于这个主题的信息。但是谢谢你的回答谢谢,看起来很好!我本来想在有时间实施后回复,但这不会很快发生。在我测试过之后,我会接受答案的。
public class ClockTextField extends TextView implements ClockListener {
public ClockTextField(Context context) {
super(context);
}
public void timeChanged(String newTime) {
setText(newTime);
}
public void register(BundleContext bundleContext) {
// remember to hold on to the service registration, so you can pull the service later.
// Better yet, think about using a dependency management tool.
bundleContext.registerService(ClockListener.class, this, null);
}
}