title: java.lang.SecurityException: No permission to write APN settings
body: <p>In my android application, i want to change the device APN with android code. but it gives the Security Exception. i did many searches on google but didn't get any answer. if anyone know about this security exception solution then help me. </p>
  
  <pre><code>Intent intent = new Intent(android.provider.Settings.ACTION_APN_SETTINGS);
                  addApn(intent,MainActivity.this);
                  startActivityForResult(intent,1);
  </code></pre>
  
  <p>i used this method to post static data on APN Settings.</p>
  
  <pre><code> private void addApn(Intent intent, Context context) {
          final String apn = intent.getStringExtra("www.airtelgprs.com");
          final String name = intent.getStringExtra("airtel");
          final String type = intent.getStringExtra("ope");
          final String proxy = intent.getStringExtra("12.25.25");
          final int mnc = intent.getIntExtra("mnc", 6);
          final int mcc = intent.getIntExtra("mcc", 724);
          final String user = intent.getStringExtra("SAnjeev");
          final String password = intent.getStringExtra("123456789");
          final String server = intent.getStringExtra("mera server");
  
          final ContentResolver cr = context.getContentResolver();
          ContentValues values = new ContentValues();
          values.put(Telephony.Carriers.APN, apn);
          values.put(Telephony.Carriers.NAME, name);
          values.put(Telephony.Carriers.TYPE, type);
          values.put(Telephony.Carriers.PROXY, proxy);
          values.put(Telephony.Carriers.MNC, mnc);
          values.put(Telephony.Carriers.MCC, mcc);
          values.put(Telephony.Carriers.USER, user);
          values.put(Telephony.Carriers.PASSWORD, password);
          values.put(Telephony.Carriers.SERVER, server);
          cr.insert(Telephony.Carriers.CONTENT_URI, values);
  
      }
  
  
  
        &lt;uses-permission android:name="android.permission.WRITE_APN_SETTINGS"
              tools:ignore="ProtectedPermissions" /&gt;
  
  
  java.lang.SecurityException: No permission to write APN settings
          at android.os.Parcel.readException(Parcel.java:1620)
          at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
          at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
          at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
          at android.content.ContentResolver.query(ContentResolver.java:493)
          at android.content.ContentResolver.query(ContentResolver.java:435)
  </code></pre>