写了一个关于网络设置的Demo程序,供学习参考。
package com.vpdn;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
/**
* 手机网络设置工具类
*/
public class arcVPDN
{
private static final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers");
private static final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn");
private Context gContext= null;
private int gDefaultApn= -1;
public arcVPDN(Context _context)
{
gContext= _context;
gDefaultApn= Default( );
}
/**
* 根据手机网络名称判断是否存在
* @param _name
* @return
*/
public boolean Exisit(String _name)
{
Cursor mCursor = gContext.getContentResolver().query(APN_TABLE_URI, null, null, null, null);
while(mCursor != null && mCursor.moveToNext())
{
String name = mCursor.getString(mCursor.getColumnIndex("name"));
if(_name.equals(name)) return true;
}
return false;
}
/**
* 添加vpdn
* @param _name
* @param _apn
* @param _user
* @param _pwd
*/
public void AddApn(String _name, String _apn, String _user, String _pwd)
{
ContentResolver resolver = gContext.getContentResolver( );
ContentValues values = new ContentValues( );
values.put("name", _name);
values.