Delete APN (Reset to Default)

Paul picture Paul · Nov 9, 2011 · Viewed 7.7k times · Source

How can I program the "Reset to default" function from the APN menu in Android?
I used the code from http://blogs.msdn.com/b/zhengpei/archive/2009/10/13/managing-apn-data-in-google-android.aspx to create and set a custom APN. However, I would like to add functionality to my script to remove the custom entry from the APN list.
Is there a way to call the "Reset to default" function?
If not, how can I remove an APN? Thanks.

Answer

Reno picture Reno · Nov 10, 2011

If not, how can I remove an APN?

If you know which entry to delete, use ContentResolver.delete()

Here the URI will be : Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers"); and Where will be a filter to apply to rows before deleting, formatted as an SQL WHERE clause (excluding the WHERE itself).

Is there a way to call the "Reset to default" function?

To restore to default you need backup the default APN ID in the first place. If you back it up, you can call SetDefaultAPN() to restore it.

Try this out though, I saw it in TelephonyProvider.java. It seems risky so I suggest you back up your APN's

private void restoreDefaultAPN() {
        SQLiteDatabase db = mOpenHelper.getWritableDatabase();

        db.delete(CARRIERS_TABLE, null, null);
        setPreferredApnId((long)-1);
        ((DatabaseHelper) mOpenHelper).initDatabase(db);
    }