Android APN切换

Android APN切换
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,
                
null null null null );
        
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, 
null null );
    }    
}
还需要加个APN设置权限
< uses-permission  android:name ="android.permission.WRITE_APN_SETTINGS"   />


---------------------------------------------------------
专注移动开发
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian

你可能感兴趣的:(Android APN切换)