Android 对于 APN 的网络 API 没有公开,不过我们可以阅读源代码,然后进行数据库操
作,系统会自动监听数据库的变化,从而实现开启或者关闭 APN。
content://telephony/carriers //取得全部 apn 列表
content://telephony/carriers/preferapn //取得当前设置的 apn
content://telephony/carriers/current //取得 current=1 的 apn 列表
这篇文章包含取得 apn 列表和设置 apn
public class APNList extends ListAcvity implements OnItemClickListener{
public stac $nal Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
public stac $nal Uri PREFERRED_APN_URI
=Uri.parse("content://telephony/carriers/preferapn");
public stac $nal Uri CURRENT_APN_URI
=Uri.parse("content://telephony/carriers/current");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor cr = this.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
String[] mStrings=new String[cr.getCount()];
int i=0;
while(cr!=null && cr.moveToNext()){
mStrings[i]="ID:"+cr.getString(cr.getColumnIndex("_id"))+
""+"name:"+cr.getString(cr.getColumnIndex("name"))+
""+"numeric:"+cr.getString(cr.getColumnIndex("numeric"))+
""+"mcc:"+cr.getString(cr.getColumnIndex("mcc"))+
""+"mnc:"+cr.getString(cr.getColumnIndex("mnc"))+
""+"apn:"+cr.getString(cr.getColumnIndex("apn"))+
""+"user:"+cr.getString(cr.getColumnIndex("user"))+
""+"server:"+cr.getString(cr.getColumnIndex("server"))+
""+"password:"+cr.getString(cr.getColumnIndex("password"))+
""+"proxy:"+cr.getString(cr.getColumnIndex("proxy"))+
""+"port:"+cr.getString(cr.getColumnIndex("port"))+
""+"mmsproxy:"+cr.getString(cr.getColumnIndex("mmsproxy"))+
""+"mmsport:"+cr.getString(cr.getColumnIndex("mmsport"))+
""+"mmsc:"+cr.getString(cr.getColumnIndex("mmsc"))+
评论1