代码设置apn,上代码:
public class APNActivity extends Activity {
public static final Uri APN_URI = Uri.parse("content://telephony/carriers");
public static final Uri CURRENT_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int _3gWapId = addAPN();
SetAPN(_3gWapId);
}
//新增一个3GWap接入点
public int addAPN() {
int id = -1;
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();
values.put("name", "3gwap");
values.put("apn", "3gwap");
values.put("mcc", "460");
values.put("mnc", "01");
values.put("numeric", "46001");
Cursor c = null;
Uri newRow = resolver.insert(APN_URI, values);
if (newRow != null) {
c = resolver.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 void SetAPN(int id) {
ContentResolver resolver = this.getContentResolver();
ContentValues values = new ContentValues();
values.put("apn_id", id);
resolver.update(CURRENT_APN_URI, values, null, null);
}
}
本文提供了一个使用Java编写的示例代码,演示了如何通过代码设置Android设备上的APN(接入点名称)。具体包括添加一个新的3G WAP APN并将其设为当前使用的APN。
873

被折叠的 条评论
为什么被折叠?



