http://blog.csdn.net/tibib/article/details/8811759
前几天接到个需求,如何根据一个基础的Android App来生成100个或更多的App,要求App icon和App name都不一样(可能还会有配置文件)。这个有点类似于为App贴上自己的标签,但具体功能由别人提供,有点类似于OEM,下面来分析下如何实现
准备工作
1、配置好Java开发环境
2、下载google提供的apk编译和反编译工具 (包含apktool.jar、apktool.bat、aapt.exe三个文件)
3、下载google提供的签名工具(包含sign.bat、signapk.jar两个文件)
icon覆盖和strings文件修改
- android:icon="@drawable/ic_launcher"
- ndroid:label="@string/app_name"
我们只要覆盖drawable-*下对应名字的icon图片和修改values-*路径下strings.xml中对应名字的属性值就行了,为了简单起见在这里以drawable-hdpi和values-zh-rCN路径来介绍
[java]
copy
- /**
- *@authorTibib
- *
- */
- publicclassAndroidManifestParser{
- publicStringNS="http://schemas.android.com/apk/res/android";
- publicAppInfoparse(InputStreamin)throwsException{
- try{
- //使用pull解析库
- XmlPullParserparser=XmlPullParserFactory.newInstance().newPullParser();
- NS=parser.getNamespace();
- //设置使用namespaces特性
- parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES,true);
- parser.setInput(in,"UTF-8");
- parser.nextTag();
- returnreadAppInfo(parser);
- }catch(Exceptione){
- e.printStackTrace();
- throwe;
- }finally{
- in.close();
- }
- }
- privateAppInforeadAppInfo(XmlPullParserparser)throwsException{
- AppInfoappInfo=newAppInfo();
- while(parser.next()!=XmlPullParser.END_TAG){
- if(parser.getEventType()!=XmlPullParser.START_TAG){
- continue;
- Stringname=parser.getName();
- //StartsbylookingfortheGeneraltag
- if("application".equals(name)){
- StringattrLabelValue=parser.getAttributeValue(NS,"label");
- StringattrIconValue=parser.getAttributeValue(NS,"icon");
- appInfo.setAppName(attrLabelValue.split("/")[1]);
- appInfo.setIconName(attrIconValue.split("/")[1]);
- else{
- skip(parser);
- returnappInfo;
- //Skipstagstheparserisn'tinterestedin.Usesdepthtohandlenestedtags.i.e.,
- //ifthenexttagafteraSTART_TAGisn'tamatchingEND_TAG,itkeepsgoinguntilit
- //findsthematchingEND_TAG(asindicatedbythevalueof"depth"being0).
- privatevoidskip(XmlPullParserparser)throwsXmlPullParserException,IOException{
- thrownewIllegalStateException();
- intdepth=1;
- while(depth!=0){
- switch(parser.next()){
- caseXmlPullParser.END_TAG:
- depth--;
- break;
- caseXmlPullParser.START_TAG:
- depth++;
- break;
- }