添加并设置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) {
		}

	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值