网络配置 - 定制APN

一、概述

      Android的网络配置作为资源文件写入了XML(/frameworks/base/core/res/res/xml/apns.xml),这个资源文件作为Android的默认Apns配置,不建议修改该文件。
     因为Apn的配置是根据不同的硬件产品而不同,所以为不同的硬件产品建立各自的配置文件(system/etc/apns-conf.xml) ,而不要去改动默认的配置文件(apns.xml)。

 

二、TelephonyProvider.java

该类用于设置APN,如果源码提供的设置不能满足你的要求,一般可以通过修改这个类来满足。

下面的代码是initDatabase函数。它主要是用来读取apns.xml(com.android.internal.R.xml.apns)和/system/etc/apns-conf.xml文件中的配置数据,用此来初始化carriers表。
private void initDatabase(SQLiteDatabase db) { // Read internal APNS data Resources r = mContext.getResources(); XmlResourceParser parser = r.getXml(com.android.internal.R.xml.apns); int publicversion = -1; try { XmlUtils.beginDocument(parser, "apns"); publicversion = Integer.parseInt(parser.getAttributeValue(null, "version")); loadApns(db, parser); } catch (Exception e) { Log.e(TAG, "Got exception while loading APN database.", e); } finally { parser.close(); } // Read external APNS data (partner-provided) XmlPullParser confparser = null; // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system". File confFile = new File(Environment.getRootDirectory(), PARTNER_APNS_PATH); FileReader confreader = null; try { confreader = new FileReader(confFile); confparser = Xml.newPullParser(); confparser.setInput(confreader); XmlUtils.beginDocument(confparser, "apns"); // Sanity check. Force internal version and confidential versions to agree int confversion = Integer.parseInt(confparser.getAttributeValue(null, "version")); if (publicversion != confversion) { throw new IllegalStateException("Internal APNS file version doesn't match " + confFile.getAbsolutePath()); } loadApns(db, confparser); } catch (FileNotFoundException e) { // It's ok if the file isn't found. It means there isn't a confidential file // Log.e(TAG, "File not found: '" + confFile.getAbsolutePath() + "'"); } catch (Exception e) { Log.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e); } finally { try { if (confreader != null) confreader.close(); } catch (IOException e) { } } }  

你可能感兴趣的:(exception,android,网络,File,null,Parsing)