android – 使用代码创建网络访问点名称,

android – 使用代码创建网络访问点名称,,第1张

概述我想通过代码创建APN,在 Android SDK中是否有任何支持,我已经尝试了很多但没有成功,我发现了一些与此 http://blogs.msdn.com/b/zhengpei/archive/2009/10/13/managing-apn-data-in-google-android.aspx相关的信息我使用此参考创建了一个类,但无法做任何事情,可以请任何给出解决方案???? 谢谢 我举几个例 我想通过代码创建APN,在 Android SDK中是否有任何支持,我已经尝试了很多但没有成功,我发现了一些与此 http://blogs.msdn.com/b/zhengpei/archive/2009/10/13/managing-apn-data-in-google-android.aspx相关的信息我使用此参考创建了一个类,但无法做任何事情,可以请任何给出解决方案????
谢谢解决方法 我举几个例子:

获取默认APN信息:

//path to APN tablefinal Uri APN_table_URI = Uri.parse("content://telephony/carrIErs");//path to preffered APNsfinal Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carrIErs/preferapn");//receiving cursor to preffered APN tableCursor c = getContentResolver().query(PREFERRED_APN_URI,null,null);//moving the cursor to beggining of the tablec.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 columnShort ID = c.getShort(index);           //getting APN's ID from//we can get APN name by the same wayindex = 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 tableint ID = -1;ContentResolver resolver = this.getContentResolver();ContentValues values = new ContentValues();//create value,you can define any other APN propertIEs in the same wayvalues.put("name","Your APN name");    //choose APN name,like 3G Orangevalues.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() methodvalues.put("mcc","your operator numeric high part");  //for example 242values.put("mnc","your operator numeric low part");   //for example 501values.put("numeric","your operator numeric");        //for example 242501Cursor 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);        //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 defaultvalues = new ContentValues();values.put("apn_ID",ID); try{    resolver.update(PREFERRED_APN_URI,values,null);}catch (Exception e){}

所以,它必须工作,但如果不是 – 告诉我,我会尝试检查问题.

总结

以上是内存溢出为你收集整理的android – 使用代码创建网络访问点名称,全部内容,希望文章能够帮你解决android – 使用代码创建网络访问点名称,所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1134139.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存