Android APN设置接口

APN(Access Point Name),即“接入点名称”,用来标识GPRS的业务种类,目前分为两大类:CMWAP(通过GPRS访问WAP业务)、CMNET(除了WAP以外的服务目前都用CMNET,比如连接因特网等)。在做项目的时候,客户会要求更换APN,我在frameworks/base/services/core/java/com/android/server/customized/CustomizedService.java中实现了这些接口,下面我把APN的接口展示如下:

    public List selectAPN(String mNumeric){
	    String where = "numeric=\"" + mNumeric + "\"";
	    List l=new ArrayList();
	    Cursor cr = mContext.getContentResolver().query(mUri, null, where, null, null);
	    while(cr != null && cr.moveToNext()){
	    ContentValues values = new ContentValues();
        values.put("id", cr.getString(cr.getColumnIndex("_id")));
        values.put("name", cr.getString(cr.getColumnIndex("name")));
        values.put("numeric", cr.getString(cr.getColumnIndex("numeric")));
        values.put("mcc", cr.getString(cr.getColumnIndex("mcc")));
        values.put("mnc", cr.getString(cr.getColumnIndex("mnc")));
        values.put("apn", cr.getString(cr.getColumnIndex("apn")));
        values.put("user", cr.getString(cr.getColumnIndex("user")));
        values.put("server", cr.getString(cr.getColumnIndex("server")));
        values.put("password", cr.getString(cr.getColumnIndex("password")));
        values.put("proxy", cr.getString(cr.getColumnIndex("proxy")));
        values.put("prot", cr.getString(cr.getColumnIndex("port")));
        values.put("authtype", cr.getString(cr.getColumnIndex("authtype")));
        values.put("type", cr.getString(cr.getColumnIndex("server")));
 	l.add(values);
	}
	return l;
    }	  

    public int deleteAPN(String id){
        return mContext.getContentResolver().delete(mUri, "_id=" + id, null);
    }

  
    public int addAPN(String name,String numeric,String mcc,String mnc,String apn,String user,String server,String password,String proxy,String port,String authtype,String type){
	    int id = -1;
        ContentValues values = new ContentValues();
		values.put("name", name);
		values.put("apn", apn);
		values.put("type", type);
		values.put("numeric", numeric);
		values.put("mcc", mcc);
		values.put("mnc", mnc);			
		values.put("port", port);
		values.put("proxy", proxy);
		values.put("user", user);
		values.put("server", server);
	    values.put("password", password);
		values.put("authtype", authtype);
		Cursor c = null;
		Uri newRow = mContext.getContentResolver().insert(mUri, values);
		if (newRow != null) {
			c = mContext.getContentResolver().query(newRow, null, null, null, null);
			int idIndex = c.getColumnIndex("_id");
			c.moveToFirst();
			id = c.getShort(idIndex);
		}
		if (c != null)
			c.close();
		return id;
	}
	

    public int updateAPN(String id,String name,String numeric,String mcc,String mnc,String apn,String user,
	String server,String password,String proxy,String port,String authtype,String type){
		ContentValues values = new ContentValues();
		int idback=-1;
		String where = "_id=\"" + id + "\"";
		values.put("name", name);
		values.put("apn", apn);
		values.put("type", type);
		values.put("numeric", numeric);
		values.put("mcc", mcc);
		values.put("mnc", mnc);			
		values.put("port", port);
		values.put("proxy", proxy);
		values.put("user", user);
		values.put("server", server);
		values.put("password", password);
		values.put("authtype", authtype);
		idback=mContext.getContentResolver().update(mUri, values, where, null);
		return idback;
    }	


    public void setDefalutApn(String id) {	
	    ContentValues values = new ContentValues();
	    values.put("apn_id", id);
	    mContext.getContentResolver().update(Uri.parse(PREFERRED_APN_URI), values, null, null);
    }

接口实现如上,该导入的包不要忘记了~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值