SalmanShariati SalmanShariati - 5 months ago 64
Android Question

Get "No permission to write APN settings" error on android 6

My application works fine on Android 5.0 and below, but when I tried to run it on a device with Android 6.0 or higher, I got this error:

Writing exception to parcel
java.lang.SecurityException: No permission to write APN settings
at android.content.ContentProvider.query(
at android.content.ContentProvider$Transport.query(
at android.content.ContentProviderNative.onTransact(
at android.os.Binder.execTransact(

Any help would be appreciated.

Answer Source

Maybe you're not getting permission in runtime. so do this

    int permissionCheck = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_APN_SETTINGS);
    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        //requesting permission
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_APN_SETTINGS}, 1);
    } else {
        //permission is granted and you can change APN settings

public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
    switch (requestCode) {
        case 1: {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                //premission granted by user
            } else {
                //permission denied by user
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download