Public class apnutil {<br/> Private Static URI preferred_apn_uri = URI <br/>. parse ("content: // telephony/carriers/preferapn"); <br/> Public static final string apn_id = "apn_id "; <br/> Private Static final int id_index = 0; </P> <p>/** <br/> * Get apntype <br/> * @ Param context <br/> * @ return <br/> */<br /> Public static string getapntype (context) {<br/> string apntype = "nomatch"; <br/> cursor C = Context. getcontentresolver (). Query (preferred_apn_uri, <br/> null, null, null); <br/> If (C! = NULL & C. getcount ()> = 1) {<br/> C. movetofirst (); <br/> string user = C. getstring (C. getcolumnindex ("user"); <br/> If (user. startswith (apnnet. ctnet) {<br/> apntype = apnnet. ctnet; <br/>} else if (user. startswith (apnnet. ctwap) {<br/> apntype = apnnet. ctwap; <br/>}< br/> C. close (); <br/> return apntype; <br/>}</P> <p> Public static void setselectedapnkey (context, string key) {<br/> contentresolver resolver = context. getcontentresolver (); <br/> contentvalues values = new contentvalues (); <br/> values. put (apn_id, key); <br/> resolver. update (preferred_apn_uri, values, null, null); <br/>}< br/>}
In addition, you must add the APN permission change.
<Uses-Permission Android: Name = "android. Permission. write_apn_settings"/>