增添并设置APN
添加并设置APN
/** * 向系统apn表中插入cmnet apn * * @param context * @param name * APN名称 * @param apn * apn * */ private static void InsertAPN(final Context context, final String name, final String apn) { int id = -1; ContentResolver resolver = context.getContentResolver(); ContentValues values = new ContentValues(); values.put("name", name); values.put("apn", apn); values.put("numeric", "46001"); values.put("proxy", ""); values.put("type", "default"); values.put("mcc", "460"); values.put("mnc", "01"); values.put("port", ""); values.put("mmsproxy", ""); values.put("mmsport", ""); values.put("user", ""); values.put("server", ""); values.put("password", ""); values.put("mmsc", ""); Cursor c = null; try { Uri newRow = resolver.insert(APN_TABLE_URI, values); if (newRow != null) { c = resolver.query(newRow, null, null, null, null); int idindex = c.getColumnIndex("_id"); c.moveToFirst(); id = c.getShort(idindex); } } catch (SQLException e) { } if (c != null) { c.close(); } SetNowAPN(context, id); } /** * 把指定的apn设置为当前的apn * * @param context * @param id * 系统数据库表中要设置为当前apn的id值 * */ private static void SetNowAPN(final Context context, final int id) { ContentResolver resolver = context.getContentResolver(); ContentValues values = new ContentValues(); values.put("apn_id", id); try { resolver.update(PREFERRED_APN_URI, values, null, null); } catch (SQLException e) { } }