After android4.0, the system signature is required and the apk is placed under the system/app.
[Html]
<Uses-permission android: name = "android. permission. ACCESS_NETWORK_STATE">
</Uses-permission>
<Uses-permission android: name = "android. permission. WRITE_APN_SETTINGS">
</Uses-permission>
<Uses-permission android: name = "android. permission. READ_PHONE_STATE"/>
<Uses-permission android: name = "android. permission. MODIFY_PHONE_STATE"/>
<Uses-permission android: name = "android. permission. ACCESS_NETWORK_STATE">
</Uses-permission>
<Uses-permission android: name = "android. permission. WRITE_APN_SETTINGS">
</Uses-permission>
<Uses-permission android: name = "android. permission. READ_PHONE_STATE"/>
<Uses-permission android: name = "android. permission. MODIFY_PHONE_STATE"/>
[Java]
Package com. lenovo. testapn;
Import android. app. Activity;
Import android. content. ContentResolver;
Import android. content. ContentValues;
Import android. content. Context;
Import android. database. Cursor;
Import android.net. Uri;
Import android. OS. Bundle;
Import android. telephony. TelephonyManager;
Import android. util. Log;
Import android. view. Menu;
Public class MainActivity extends Activity {
Private static final String TAG = "MainActivity ";
Public static final Uri APN_URI = Uri. parse ("content: // telephony/carriers ");
// Public static final Uri PREFERRED_APN_URI
// = Uri. parse ("PREFERRED_APN_URI ");
Public static final Uri CURRENT_APN_URI = Uri
. Parse ("content: // telephony/carriers/preferapn ");
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
Log. d (TAG, "onCreate ");
CheckAPN ();
// SetAPN (addAPN ());
}
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
// Inflate the menu; this adds items to the action bar if it is present.
GetMenuInflater (). inflate (R. menu. activity_main, menu );
Return true;
}
Public void checkAPN (){
// Check the APN of the current connection
Cursor cr = getContentResolver (). query (APN_URI, null );
Log. d (TAG, "cr" + cr );
While (cr! = Null & cr. moveToNext ()){
// If (cr. getString (cr. getColumnIndex ("_ id ")))
// APN id
String id = cr. getString (cr. getColumnIndex ("_ id "));
Log. d (TAG, "id" + id );
// String apn_id = cr. getString (cr. getColumnIndex ("apn_id "));
//
// Log. d (TAG, "apn_id" + apn_id );
// APN name
String apn = cr. getString (cr. getColumnIndex ("apn "));
Log. d (TAG, apn );
// Toast. makeText (getApplicationContext (),
// "Current id:" + id + "apn:" + apn, Toast. LENGTH_LONG). show ();
}
}
// Add a cmnet Access Point
Public int addAPN (){
Int id =-1;
Log. d (TAG, "Add a new apn ");
String NUMERIC = getSIMInfo ();
Log. d (TAG, "NUMERIC" + NUMERIC );
If (NUMERIC = null ){
Return-1;
}
ContentResolver resolver = this. getContentResolver ();
ContentValues values = new ContentValues ();
SIMCardInfo siminfo = new SIMCardInfo (MainActivity. this );
// String user = siminfo. getNativePhoneNumber (). substring (start );
Values. put ("name", "specialized APN"); // Chinese description of apn
Values. put ("apn", "myapn"); // apn name
Values. put ("type", "default, supl ");
Values. put ("numeric", NUMERIC );
Values. put ("mcc", NUMERIC. substring (0, 3 ));
Values. put ("mnc", NUMERIC. substring (3, NUMERIC. length ()));
Values. put ("proxy ","");
Values. put ("port ","");
Values. put ("mmsproxy ","");
Values. put ("mmsport ","");
Values. put ("user ","");
Values. put ("server ","");
Values. put ("password ","");
Values. put ("mmsc ","");
Cursor c = null;
Uri newRow = resolver. insert (APN_URI, values );
If (newRow! = Null ){
C = resolver. query (newRow, null, null );
Int idIndex = c. getColumnIndex ("_ id ");
C. moveToFirst ();
Id = c. getShort (idIndex );
}
If (c! = Null)
C. close ();
Return id;
}
Protected String getSIMInfo (){
TelephonyManager iPhoneManager = (TelephonyManager) this
. GetSystemService (Context. TELEPHONY_SERVICE );
Return iPhoneManager. getSimOperator ();
}
// Set the Access Point
Public void SetAPN (int id ){
ContentResolver resolver = this. getContentResolver ();
ContentValues values = new ContentValues ();
Values. put ("apn_id", id );
Resolver. update (CURRENT_APN_URI, values, null, null );
// Resolver. delete (url, where, selectionArgs)
}
}