本文转载自:http://blog.csdn.net/catoop/article/details/50435431
安卓开发完成,对于一个开放应用而言,我们需要发布到不同的应用市场,同时我们也需要统计不同市场的用户下载量。(通过启动应用后获取不同市场apk中的不同值来区分)
下面用一个具体的实例来说明:
1、在AndroidManifest.xml的application内添加meta-data标签
<code class="hljs xml has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial; "><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; "><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); ">application </span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102); ">android:allowBackup</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0); ">"true"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102); ">android:icon</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0); ">"@drawable/ic_launcher"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102); ">android:label</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0); ">"@string/app_name"</span>></span> <span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; "><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); ">meta-data </span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102); ">android:name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0); ">"APP_CHANNEL"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102); ">android:value</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0); ">"${APP_CHANNEL_VALUE}"</span> /></span> <span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; "><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); ">activity </span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102); ">android:name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0); ">".MainActivity"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102); ">android:label</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0); ">"@string/app_name"</span> ></span> <span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; "><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); ">intent-filter</span>></span> <span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; "><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); ">action</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102); ">android:name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0); ">"android.intent.action.MAIN"</span> /></span> <span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; "><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); ">category</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102); ">android:name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0); ">"android.intent.category.LAUNCHER"</span> /></span> <span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; "></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); ">intent-filter</span>></span> <span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; "></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); ">activity</span>></span> <span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; "></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136); ">application</span>></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; "><li style="box-sizing: border-box; padding: 0px 5px; ">1</li><li style="box-sizing: border-box; padding: 0px 5px; ">2</li><li style="box-sizing: border-box; padding: 0px 5px; ">3</li><li style="box-sizing: border-box; padding: 0px 5px; ">4</li><li style="box-sizing: border-box; padding: 0px 5px; ">5</li><li style="box-sizing: border-box; padding: 0px 5px; ">6</li><li style="box-sizing: border-box; padding: 0px 5px; ">7</li><li style="box-sizing: border-box; padding: 0px 5px; ">8</li><li style="box-sizing: border-box; padding: 0px 5px; ">9</li><li style="box-sizing: border-box; padding: 0px 5px; ">10</li><li style="box-sizing: border-box; padding: 0px 5px; ">11</li><li style="box-sizing: border-box; padding: 0px 5px; ">12</li><li style="box-sizing: border-box; padding: 0px 5px; ">13</li><li style="box-sizing: border-box; padding: 0px 5px; ">14</li><li style="box-sizing: border-box; padding: 0px 5px; ">15</li><li style="box-sizing: border-box; padding: 0px 5px; ">16</li><li style="box-sizing: border-box; padding: 0px 5px; ">17</li><li style="box-sizing: border-box; padding: 0px 5px; ">18</li><li style="box-sizing: border-box; padding: 0px 5px; ">19</li></ul>
2、修改build.gradle文件,在android {} 中添加
<code class="hljs cs has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial; ">android { <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; ">// 打包渠道List&