创建网络接入点名称与code, [英] Create Network Access Point Name with code,

查看:146
本文介绍了创建网络接入点名称与code,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过code创建APN,有没有在Android SDK中的任何支持,我已经尝试了很多,但没有成功,我发现了一些信息与此相关的http://blogs.msdn.com/b/zhengpei/archive/2009/10/13/managing-apn-data-in-google-android.aspx我做了使用这个引用一个类,但不能做任何事情,可以在任何请给这个解决方案???? 谢谢

I want to create APN by code, is there any support in Android SDK, i have tried a lot but not succeed,I found some info related to this http://blogs.msdn.com/b/zhengpei/archive/2009/10/13/managing-apn-data-in-google-android.aspx i made a class using this reference but not able to do anything,can any please give the solution for this???? Thanks

推荐答案

我会举一些例子:

获取默认的APN信息:

Getting default APN information:

//path to APN table
final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");

//path to preffered APNs
final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");

//receiving cursor to preffered APN table
Cursor c = getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);

//moving the cursor to beggining of the table
c.moveToFirst();

//now the cursor points to the first preffered APN and we can get some
//information about it
//for example first preffered APN id    
int index = c.getColumnIndex("_id");    //getting index of required column
Short id = c.getShort(index);           //getting APN's id from

//we can get APN name by the same way
index = c.getColumnIndex("name");
String name = c.getString(index); 

//and any other APN properties: numeric, mcc, mnc, apn, user, server,
//password, proxy, port, mmsproxy, mmsport, mmsc, type, current

要定义新的APN:

//first we have to create a new row in APN table
int id = -1;
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();

//create value, you can define any other APN properties in the same way
values.put("name", "Your APN Name");    //choose APN name, like 3G Orange
values.put("apn", "Your APN address");  //choose APN address, like cellcom.wapu.co.il

//now we have to define APN setting page UI. You have to get operator numeric property
//you can obtain it from TelephonyManager.getNetworkOperator() method
values.put("mcc", "your operator numeric high part");  //for example 242
values.put("mnc", "your operator numeric low part");   //for example 501
values.put("numeric", "your operator numeric");        //for example 242501

Cursor c = null;
try
{
    //insert new row to APN table
    Uri newRow = resolver.insert(APN_TABLE_URI, values);
    if(newRow != null)
    {
        c = resolver.query(newRow, null, null, null, null);

        //obtain the APN id
        int index = c.getColumnIndex("_id");
        c.moveToFirst();
        id = c.getShort(index);
    }
}
catch(Exception e)
{
}

//now after we created a new APN in APN table
//and APN's ID stored in id variable (or -1 if any troubles was happaned)
//we can define a new APN as default
values = new ContentValues();
values.put("apn_id", id); 

try
{
    resolver.update(PREFERRED_APN_URI, values, null, null);
}
catch (Exception e)
{
}

因此​​,它有工作,但如果没有 - 告诉我,我会尽量研究的问题

so, it have to work, but if it not - tell me and I will try to examine problems.

这篇关于创建网络接入点名称与code,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆