代码设置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); } }