2

I use the following code in oder to get the preferred apn of the device:

DefaultHttpClient http = new DefaultHttpClient();
Cursor mCursor = ctx.getContentResolver().query(Uri.parse("content://telephony/carriers/preferapn"), new String[] { "name", "proxy", "port"},null, null, null);

if a proxy is set i modify my webrequest

if (mCursor != null) {
            try {
                if (mCursor.moveToFirst()) {
                    // String name = mCursor.getString(0);
                    String proxy = mCursor.getString(1);
                    String port = mCursor.getString(2);
                    if (proxy != null) {
                        if (!proxy.equals("")) {
                            HttpHost proxys = new HttpHost(proxy, Integer.parseInt(port));
                            http.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxys);
                        }
                    }

                }
            } finally {
                try {
                    mCursor.close();
                } catch (Exception e) {
                    mCursor = null;
                }
                mCursor = null;
            }
        }

since Android 4.2 the code failed due to a security exception, neither the user non the Process have the permission WRITE_APN_SETTINGS. I added and but nothing works. Does anybody know how to fix that?

2red13
  • 11,197
  • 8
  • 40
  • 52
  • feels like a 4.2 bug to me. _reading_ the apn settings should be still allowed. might be worth filing a bug on http://code.google.com/p/android/issues/ PS, what rom? stock 4.2, 4.2.1, CyanogenMod 10.1, etc? – SteelBytes Dec 28 '12 at 04:34

1 Answers1

1

WRITE_APN_SETTINGS

is now system level permission now:

"Ice Cream Sandwich" and WRITE_APN_SETTINGS

It seems you need to set your application as System app to be able to use APN settings, and that requires a rooted phone.

Community
  • 1
  • 1
Caner
  • 57,267
  • 35
  • 174
  • 180
  • 1
    `WRITE_APN_SETTINGS` is not "ignored in ICS". It is a `signature|system` permission now, and so it can only be held by apps that are signed by the firmware signing key or are installed on the system partition. Android 4.0 made that change; Android 4.2 made *reading* APN data also be secured via `WRITE_APN_SETTINGS`: http://commonsware.com/blog/2012/11/20/miscellaneous-android-4p2-regressions.html – CommonsWare Nov 22 '12 at 15:42
  • This seems to be tho point. Nevertheless i don't understand why WRITE_APN is a problem for reading the settings... Rooting is not an option, so i have to force the users with a proxy in the apn to store the proxy and the port in the settings of my app :( – 2red13 Nov 23 '12 at 12:40