GCM with custom broadcastreceiver

后端 未结 4 382
隐瞒了意图╮
隐瞒了意图╮ 2020-12-28 11:14

I am implementing gcm notifications in my application. Because I use my code to generate lot of application with different package names I cannot use standard mypackage.GCMI

4条回答
  •  萌比男神i
    2020-12-28 11:40

    Because I use my code to generate lot of application with different package names I cannot use standard mypackage.GCMIntentService name.

    I'm not sure whether you ask for a runtime or a build time solution. The other answers are runtime solutions so I thought I add some information on possibilites during build time.


    In AndroidManifest, you can use the variable $PACKAGE_NAME (available by default) which will refer to the package name you specified in the attribute package in the manifest root element.

    The value of this package attribute needs not be a hard coded string but can also be set dynamically via resource reference like so:

    
        ...
        
        ...
    
    

    Note .service is just a subpackage that I included to show how you specify these. Of course, this solution would work only if your applications follow general rules like putting Service classes in a .service subpackage.

    Also note, that you can actually leave the root package off completely. It will be expanded by Android:

    
        ...
        
        ...
    
    

    In effect, same as above.

    If you are looking for a more flexible way to replace values in an AndroidManifest (or different files), you might want to have a look at the Ant Replace task (http://ant.apache.org/manual/Tasks/replace.html) or Resource Filtering (http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html) with Maven.

提交回复
热议问题