现在的位置: 首页 > 综合 > 正文

Android Manifest Action小笔记

2014年02月26日 ⁄ 综合 ⁄ 共 896字 ⁄ 字号 评论关闭

昨天在做库项目 因为不想把主项目的manifest搞的一堆东东,而且库项目公用的

Receiver中有个Action 但是这个问题折腾了好久,原文https://groups.google.com/forum/#!topic/android-developers/PL_sbGQ13m8

问题这样子,Action不能写死,需要各个项目单独配置,问题来了,如果@string方式引用,倒是Receiver无效。

<service android:name=".subpackage.MyService"> 
        <intent-filter> 
                <action android:name="com.company.application.subpackage.RUN"></ 
action> 
                <!-- This does not work at all, but I expect it to 
                <action android:name="@string/actionMyServiceRun"></action> 
                --> 
        </intent-filter> 
</service> 

Resource Snippet: 
        <string 
name="actionMyServiceRun">com.company.application.subpackage.RUN</ 
string> 

代码片段,这样子就收不到了 google的童鞋这样答复的

Don't do that.  The string must be in the manifest.  (It would make things much more complicated if these strings could change due to locale changes, screen orientation changes, etc.)

一堆东西,怎么搞?

最后把activity等不变化的还是留在库项目中,只把变化的在主项目中填上

在project属性文件中manifestmerger.enabled=true 

激活manifest merge 像样子就可以简化配置了,编译是自动合并manifest文件,库项目暴露的接口尽量的少,尽量降低配置的复杂度,不然做了没啥意义了

抱歉!评论已关闭.