{
resolver.update(PREFERRED_APN_URI, values, null, null);
Cursor c = resolver.query(PREFERRED_APN_URI, new String[] { \\ if (c != null) {
res = true; c.close(); } }
catch (SQLException e) { }
return res; }
public void SetDefaultAPN(int id) {
setDefaultApn(id); ConnectivityManager cm = (ConnectivityManager) this.getSystemService(CONNECTIVITY_SERVICE);
cm.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, \ Cursor cursor = getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
int rows = cursor.getCount(); cursor.moveToFirst(); String apn;
for (int i = 0; i < rows; i++) {
apn = cursor.getString(1);
Log.e(\ cursor.moveToNext(); } }
//检查指定APN是否存在 public int checkAPN() {
ApnNode checkApn = new ApnNode(); checkApn.setName(\中国电信ctnet\ checkApn.setApn(\ checkApn.setMcc(getMCC());
checkApn.setMnc(getMNC());
checkApn.setNumeric(getSimOperator()); return isApnExisted(checkApn); }
public int isApnExisted(ApnNode apnNode) {
int apnId = -1;
// Uri uri = Uri.parse(\
Cursor mCursor = getContentResolver().query(APN_TABLE_URI, null, null, null, null);
while (mCursor != null && mCursor.moveToNext()) {
apnId = mCursor.getShort(mCursor.getColumnIndex(\
String name = mCursor.getString(mCursor.getColumnIndex(\ String apn = mCursor.getString(mCursor.getColumnIndex(\ String type = mCursor.getString(mCursor.getColumnIndex(\ String proxy = mCursor.getString(mCursor.getColumnIndex(\ String port = mCursor.getString(mCursor.getColumnIndex(\ String current = mCursor.getString(mCursor.getColumnIndex(\
String mcc = mCursor.getString(mCursor.getColumnIndex(\ String mnc = mCursor.getString(mCursor.getColumnIndex(\ String numeric = mCursor.getString(mCursor.getColumnIndex(\
Log.e(\+ type + \
if (/*apnNode.getName().equals(name)*/(apnNode.getApn().equals(apn) && apnNode.getMcc().equals(mcc) && apnNode.getMnc().equals(mnc) && apnNode.getNumeric().equals(numeric)) && (type == null || \|| \(apnNode.getApn().equals(apn) && \ {
return apnId; } else {
apnId = -1; } }
return apnId; }
public int addNewApn(ApnNode apnNode)
{
int apnId = -1;
ContentResolver resolver = getContentResolver(); ContentValues values = new ContentValues(); values.put(\ values.put(\ values.put(\ values.put(\ values.put(\
values.put(\ values.put(\ values.put(\
values.put(\
// Note: this values need to be update, and for now, it only for XT800.
Cursor c = null; try {
Uri newRow = resolver.insert(APN_TABLE_URI, values); if (newRow != null) {
c = resolver.query(newRow, null, null, null, null);
int idindex = c.getColumnIndex(\ c.moveToFirst();
apnId = c.getShort(idindex);
Log.d(\\ID: \+ apnId + \Inserting new APN succeeded!\ } }
catch (SQLException e) { }
if (c != null) c.close();
return apnId; }
//添加一个APN
private void InsetAPN() {
ApnNode checkApn = new ApnNode();
checkApn.setName(\中国电信CTNET\ checkApn.setApn(\
// checkApn.setProxy(\// checkApn.setPort(\ checkApn.setUser(\
checkApn.setPassword(\ checkApn.setMcc(getMCC()); checkApn.setMnc(getMNC());
checkApn.setNumeric(getSimOperator()); apnd_id = addNewApn(checkApn); } }
4.主界面的xml文件为:
android:id=\
android:layout_width=\android:layout_height=\android:orientation=\
xmlns:android=\>
只要是开发过android的肯定清楚这些代码和界面吧,我也不多解释了,如果哥们你看不懂,那就是说明你还没弄清android开发,先去补补课再来看
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/napolun007/archive/2010/07/20/5748595.aspx
网络连接实例(接上篇APN设置) 收藏
private static final String WEBURL = \
try {
// 创建URL对象
URL url = new URL(WEBURL); // 创建URL连接 HttpURLConnection connection = (HttpURLConnection)url.openConnection();
// 对于 HTTP 连接可以直接转换成 HttpURLConnection,
// 这样就可以使用一些 HTTP 连接特定的方法,如 setRequestMethod() 等
// HttpURLConnection connection
// =(HttpURLConnection)url.openConnection(Proxy_yours); // 设置参数
connection.setConnectTimeout(10000); // 连接服务器
connection.connect();
} catch (IOException e) {
// TODO Auto-generated catch block e.printStackTrace(); }
连接Intenet网络,进行APN设置后无法直接进入网络,可以先进行下此项连接设置,就能登录网络了
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/napolun007/archive/2010/07/21/5753018.aspx