android底层oem,Android中如何实现OEM

/**

* @author Tibib

*

*/

public class AndroidManifestParser {

public String NS = "http://schemas.android.com/apk/res/android" ;

public AppInfo parse(InputStream in) throws Exception {

try {

//使用pull解析库

XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();

NS = parser.getNamespace();

//设置使用 namespaces特性

parser.setFeature(XmlPullParser. FEATURE_PROCESS_NAMESPACES , true );

parser.setInput(in, "UTF-8" );

parser.nextTag();

return readAppInfo(parser);

} catch (Exception e){

e.printStackTrace();

throw e;

} finally {

in.close();

}

}

private AppInfo readAppInfo(XmlPullParser parser) throws Exception{

AppInfo appInfo = new AppInfo();

while (parser.next() != XmlPullParser. END_TAG) {

if (parser.getEventType() != XmlPullParser. START_TAG) {

continue ;

}

String name = parser.getName();

// Starts by looking for the General tag

if ("application" .equals(name)){

String attrLabelValue = parser.getAttributeValue( NS, "label" );

String attrIconValue = parser.getAttributeValue( NS, "icon" );

appInfo.setAppName(attrLabelValue.split( "/" )[1]);

appInfo.setIconName(attrIconValue.split( "/" )[1]);

}

else {

skip(parser);

}

}

return appInfo;

}

// Skips tags the parser isn't interested in. Uses depth to handle nested tags. i.e.,

// if the next tag after a START_TAG isn't a matching END_TAG, it keeps going until it

// finds the matching END_TAG (as indicated by the value of "depth" being 0).

private void skip(XmlPullParser parser) throws XmlPullParserException, IOException {

if (parser.getEventType() != XmlPullParser. START_TAG) {

throw new IllegalStateException();

}

int depth = 1;

while (depth != 0) {

switch (parser.next()) {

case XmlPullParser. END_TAG:

depth--;

break ;

case XmlPullParser. START_TAG:

depth++;

break ;

}

}

}

}

修改strings.xml中name属性为app_name(具体名称看配置)的值

/**

* @author Tibib

*

*/

public class XmlModifyUtil {

/**

* 使用的是 jdom库

*/

public static void modifyXML(File modifyXmlFile, String appNameAttrValue,

String appNameText) {

OutputStreamWriter bos = null ;

try {

SAXBuilder builder = new SAXBuilder();

if (modifyXmlFile.exists()) {

Document document = (Document) builder.build(modifyXmlFile);

Element root = document.getRootElement();

List stringChildList = root.getChildren( "string");

for (Element element : stringChildList) {

String nameAttrValue = element.getAttribute("name" )

.getValue();

if (nameAttrValue.equals(appNameAttrValue)) {

element.setText(appNameText);

}

}

String xmlFileData = new XMLOutputter().outputString(document);

// strings.xml默认是UTF-8格式

bos = new OutputStreamWriter(

new FileOutputStream(modifyXmlFile), "UTF-8" );

bos.write(xmlFileData);

bos.flush();

} else {

System. out .println("File does not exist" );

}

} catch (Exception ex) {

ex.printStackTrace();

} finally {

if (bos != null ) {

try {

bos.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

}

执行编译和签名命令

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值