取值 1111

读取android etc目录下的xml文件【原创】 
2011-03-19 15:01
读取android etc目录下的xml文件

读取device\qsts\aspen_common\rootfs\etc目录下的xml文件,比如spn-conf.xml

<?xml version="1.0" encoding="utf-8"?>

<spnOverrides>

<!--

@Author: HTC Shawn Ku

@Date: 2010/02/23


This is a list for operator specific SPNs.

We will use below SPN for instead if numeric is matched.



Format is listed as below:

<spnOverrides

numeric="MCC+MNC"

spn="SPN Name"/>

-->

<spnOverride

numeric="44020"

spn="SoftBank"/>

<spnOverride

numeric="46000"

spn="中国移动"/>

<spnOverride

numeric="46001"

spn="中国联通"/>

<spnOverride

numeric="46002"

spn="中国移动"/>

<spnOverride

numeric="46003"

spn="中国电信"/>

<spnOverride

numeric="46005"

spn="中国电信"/>

<spnOverride

numeric="46006"

spn="中国联通"/>

<spnOverride

numeric="46007"

spn="中国移动"/>

</spnOverrides>









android java代码:

/*

* Copyright (C) 2009 The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/



package com.android.internal.telephony.gsm;



import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import java.util.HashMap;



import org.xmlpull.v1.XmlPullParser;

import org.xmlpull.v1.XmlPullParserException;



import android.os.Environment;

import android.util.Log;

import android.util.Xml;



import com.android.internal.util.XmlUtils;



public class SpnOverride {

private HashMap<String, String> CarrierSpnMap;





static final String LOG_TAG = "GSM";

static final String PARTNER_SPN_OVERRIDE_PATH ="etc/spn-conf.xml";



SpnOverride () {

CarrierSpnMap = new HashMap<String, String>();

loadSpnOverrides();

}



boolean containsCarrier(String carrier) {

return CarrierSpnMap.containsKey(carrier);

}



String getSpn(String carrier) {

return CarrierSpnMap.get(carrier);

}



private void loadSpnOverrides() {

FileReader spnReader;



final File spnFile = new File(Environment.getRootDirectory(),

PARTNER_SPN_OVERRIDE_PATH);



try {

spnReader = new FileReader(spnFile);

} catch (FileNotFoundException e) {

Log.w(LOG_TAG, "Can't open " +

Environment.getRootDirectory() + "/" + PARTNER_SPN_OVERRIDE_PATH);

return;

}



try {

XmlPullParser parser = Xml.newPullParser();

parser.setInput(spnReader);



XmlUtils.beginDocument(parser, "spnOverrides");



while (true) {

XmlUtils.nextElement(parser);



String name = parser.getName();

if (!"spnOverride".equals(name)) {

break;

}



String numeric = parser.getAttributeValue(null, "numeric");

String data = parser.getAttributeValue(null, "spn");



CarrierSpnMap.put(numeric, data);

}

} catch (XmlPullParserException e) {

Log.w(LOG_TAG, "Exception in spn-conf parser " + e);

} catch (IOException e) {

Log.w(LOG_TAG, "Exception in spn-conf parser " + e);

}

}



}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值