Posted by shen747 2 years 1 week ago
I was able to read and add APN settings programetically in android using a
content resolver as follows :
NOTE : This code is written inside a "onCreate()" method of a class
that extends an Activity.
------------
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Trying to Insert a Custom Setting to Telephony db
ContentValues values = new ContentValues();
values.put("_id","3");
values.put("name","Ramesh");
values.put("numeric","310995");
values.put("mcc","315");
values.put("mnc","995");
values.put("apn","email");
values.put("user","elkjop");
values.put("server","www.moota.com");
values.put("password","elkjop");
values.put("proxy","12");
values.put("port","12");
values.put("mmsproxy","12");
values.put("mmsport","12");
values.put("mmsc","12");
values.put("type","a");
values.put("current","a");
//Adding Values using the Content Resolver
getContentResolver().insert(Uri.parse("content://telephony/
carriers"), values);
Cursor cursor = getContentResolver().(Uri.parse("content://telephony/
carriers"),
null, null, null, null);
StringBuffer sb = new StringBuffer();
cursor.moveToFirst();
do{
sb.append("_id =").append(cursor.getString(0)).append(" , ");
sb.append("name=").append(cursor.getString(1)).append(" , ");
sb.append("numeric=").append(cursor.getString(2)).append(" , ");
sb.append("mcc=").append(cursor.getString(3)).append(" , ");
sb.append("mnc=").append(cursor.getString(4)).append(" , ");
sb.append("apn=").append(cursor.getString(5)).append(" , ");
sb.append("user=").append(cursor.getString(6)).append(" , ");
sb.append("server=").append(cursor.getString(7)).append(" , ");
sb.append("password=").append(cursor.getString(8)).append(" , ");
sb.append("proxy=").append(cursor.getString(9)).append(" , ");
sb.append("port=").append(cursor.getString(10)).append(" , ");
sb.append("mmsproxy=").append(cursor.getString(11)).append(" , ");
sb.append("mmsport=").append(cursor.getString(12)).append(" , ");
sb.append("mmsc=").append(cursor.getString(13)).append(" , ");
sb.append("type=").append(cursor.getString(14)).append(" , ");
sb.append("current=").append(cursor.getString(15)).append(" , ");
sb.append("\n--- BLOCK ---\n");
}while(cursor.moveToNext());
Log.i(LOG_IDENTIFIER,sb.toString());
startActivity(new Intent(Settings.ACTION_APN_SETTINGS));
}
-------------- Now the Issue I have is how can I do the same as above with the email settings saved in android ??. It would be great if you could provide me with the uri to do this using a content resolver as shown above !!. I've also attached the activity class file I've used to do and check this as well !!.
Thanks,
Ramesh.
| Attachment | Size |
|---|---|
| APNSettingsActivity.java_.txt | 3.45 KB |




Posted by shen747 2 years ago
Can any one help ?. Any ideas ??.
Posted by aka 35 weeks ago
Hi Shen
thank you for the code.
I will like to know if it works for you ?
I have to configure APN for much Android phone, I will like to do it automatically. I try your code but it does not work when I run the code I have the following error: "the application has stopped Unexpectedly"with a button to force quit the application.
thank you