使用代码创建网络接入点名称,

发布于 2024-12-02 16:26:11 字数 320 浏览 1 评论 0原文

我想通过代码创建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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌梦深 2024-12-09 16:26:11

我将给出一些例子:

获取默认 APN 信息:

//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)
{
}

所以,它必须工作,但如果不能 - 告诉我,我会尝试检查问题。

I will give some examples:

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

To define new 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.

不知所踪 2024-12-09 16:26:11

@博格8
谢谢,你帮了我很多,这就是我所错过的,一开始我在UI列表中看不到新的APN。
我在上面的链接@DeepSan 这里

要查看我刚刚在 ** emaltor ** UI 中创建的新 APN,我使用 310260 数字

// TelephonyProperties;
    values.put("mcc", "310");
    values.put("mnc", "260");
    values.put("numeric", "310260");

要在我的设备 (Galaxy) 上查看它,我使用了 TelephonyManager:

  TelephonyManager tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String networkOperator = tel.getNetworkOperator();
    int mcc = 0;
    int mnc = 0;
    if (networkOperator != null) {
          mcc = Integer.parseInt(networkOperator.substring(0, 3));
          mnc = Integer.parseInt(networkOperator.substring(3));
    }

   // TelephonyProperties;
    values.put("mcc", mcc );
    values.put("mnc", mnc );
    values.put("numeric",networkOperator);

现在我可以在 UI 上看到新 APN。

@Borg8
Thanks, you helped me a lot, this is what I missed, at first I could not see the new APN at the UI list.
I found my answer at @DeepSan above link here.

To see the new APN that I just created in the ** emaltor ** UI, I use the 310260 numric number

// TelephonyProperties;
    values.put("mcc", "310");
    values.put("mnc", "260");
    values.put("numeric", "310260");

To See It on my Device(Galaxy) I Used the TelephonyManager:

  TelephonyManager tel = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String networkOperator = tel.getNetworkOperator();
    int mcc = 0;
    int mnc = 0;
    if (networkOperator != null) {
          mcc = Integer.parseInt(networkOperator.substring(0, 3));
          mnc = Integer.parseInt(networkOperator.substring(3));
    }

   // TelephonyProperties;
    values.put("mcc", mcc );
    values.put("mnc", mnc );
    values.put("numeric",networkOperator);

Now I can see the new APN on the UI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文