Skip to content Skip to sidebar Skip to footer

Read Current Apn Name From Code [root]

I need to be able to read current APN name. My app is a system app (it's located under /system/app) and I have root access. I'm trying to get APN name but it's being impossible be

Solution 1:

Android 5.1 introduced Carrier Privileges (https://source.android.com/devices/tech/config/uicc).

To be possible to change the APN you have to sign your app with the same signature of the SIM card. If you do this, then it is possible to change the APN. You do not need the

<uses-permissionandroid:name="android.permission.WRITE_APN_SETTINGS"/>

in Android Manifest.

You can sign your app with Android Studio for example (https://developer.android.com/studio/publish/app-signing.html)

Solution 2:

WRITE_APN_SETTINGS

Not for use by third-party applications. You cant read the APN settings in API > 18.

For API <= 18

publicclassAPNHelper {

    private Context context;

    publicAPNHelper(final Context context) {
        this.context = context;
    }

    @SuppressWarnings("unchecked")public List<APN> getMMSApns() {
        finalCursorapnCursor=this.context.getContentResolver()
                .query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI,
                        "current"), null, null, null, null);
        if (apnCursor == null) {
            return Collections.EMPTY_LIST;
        } else {
            final List<APN> results = newArrayList<APN>();
            if (apnCursor.moveToFirst()) {
                do {
                    finalStringtype= apnCursor.getString(apnCursor
                            .getColumnIndex(Telephony.Carriers.TYPE));
                    if (!TextUtils.isEmpty(type)
                            && (type.equalsIgnoreCase("*") || type
                            .equalsIgnoreCase("mms"))) {
                        finalStringmmsc= apnCursor.getString(apnCursor
                                .getColumnIndex(Telephony.Carriers.MMSC));
                        finalStringmmsProxy= apnCursor.getString(apnCursor
                                .getColumnIndex(Telephony.Carriers.MMSPROXY));
                        finalStringport= apnCursor.getString(apnCursor
                                .getColumnIndex(Telephony.Carriers.MMSPORT));
                        finalAPNapn=newAPN();
                        apn.MMSCenterUrl = mmsc;
                        apn.MMSProxy = mmsProxy;
                        apn.MMSPort = port;
                        results.add(apn);

                        Toast.makeText(context,
                                mmsc + " " + mmsProxy + " " + port,
                                Toast.LENGTH_LONG).show();
                    }
                } while (apnCursor.moveToNext());
            }
            apnCursor.close();
            return results;
        }
    }
}

Post a Comment for "Read Current Apn Name From Code [root]"