随笔-348  评论-598  文章-0  trackbacks-0
public class ApnUtil {
    
private static Uri PREFERRED_APN_URI = Uri
    .parse(
"content://telephony/carriers/preferapn");
    
public static final String APN_ID = "apn_id";
    
private static final int ID_INDEX = 0;
    
    
/**
     * get apntype
     * 
@param context
     * 
@return
     
*/
    
public static String getApnType(Context context){
        String apntype
="nomatch";
        Cursor c 
= context.getContentResolver().query(PREFERRED_APN_URI,
                
nullnullnullnull);
        
if(c != null && c.getCount() >= 1){
            c.moveToFirst();
            String user
=c.getString(c.getColumnIndex("user"));
            
if(user.startsWith(APNNET.CTNET)){
                apntype
=APNNET.CTNET;
            }
else if(user.startsWith(APNNET.CTWAP)){
                apntype
=APNNET.CTWAP;
            }
        }
        c.close();
        
return apntype;
    }
    
    
public static void setSelectedApnKey(Context context,String key) {
        ContentResolver resolver 
= context.getContentResolver();
        ContentValues values 
= new ContentValues();
        values.put(APN_ID, key);
        resolver.update(PREFERRED_APN_URI, values, 
nullnull);
    }    
}
还需要加个APN设置权限
<uses-permission android:name="android.permission.WRITE_APN_SETTINGS" />


---------------------------------------------------------
专注移动开发

Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2010-11-16 09:54 TiGERTiAN 阅读(1211) 评论(0)  编辑  收藏 所属分类: Android

只有注册用户登录后才能发表评论。


网站导航: