开发者

How do I get the "meta-data" of my service

I have metadata in the AndroidManifest.xml for my service. Getting this metadata is fairly straightforward in an activity, as all you have to do is something like this:

final Bundle data =
getPackageManager().getActivityInfo(this.getComponentName(), PackageManager.GET_META_DATA).metaData;

For services, I would obviously be using the 'getServiceInfo()' method instead of the activi开发者_如何学运维ty info, but there is no 'getComponentName()' method in a Service. Is there any reason why this isn't available? Do I have to construct my own ComponentName object here?

Thanks


ComponentName myService = new ComponentName(this, this.getClass());
Bundle data = getPackageManager().getServiceInfo(myService, PackageManager.GET_META_DATA).metaData;


Do I have to construct my own ComponentName object here?

AFAIK, yes. From a Service, new ComponentName(this, this.getClass()) should give you a ComponentName for the service itself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜