Sort out the APN for Android

Source: Internet
Author: User

 

APN Organization

Some time ago, you added the APN setting function for your company project. Now I want to make some preparations for sharing and taking notes.

APN Field

Different mobile phones have different fields for storing APN-related data. The fields shown here are all public parts.

PublicclassAPN {

PublicStringid;

PublicStringset; // added by myself. The user confirms whether to set it to the default value.

PublicString name; // The name displayed.

PublicString APN; // Access Point name cmwap/cmnet .......

PublicString MCC; // country ID

PublicString MNC; // carrier ID

PublicString numeric; // unique identifier of the MCC + MNC operator globally

PublicString user; // User Name

PublicString password; // Password

PublicString server; // Service

PublicString proxy; // proxy

PublicString port; // Port

PublicString mmsport; // SMS Port

PublicString mmsproxy; // SMS proxy

PublicString mmsc;

PublicString authtype;

PublicString current; // when = "1", it is displayed

PublicString type; // type

}

Storage path of APN

1.
View All APN data

PublicUricreateuri = Uri.Parse("Content: // telephony/carriers ");

2.
View the APN data currently in use

Uri preferuri = Uri.Parse("Content: // telephony/carriers/preferapn ");

Increase of APN

/**

*
Create a new data

*/

PublicUriaddnewapn (APN ){

Log.I("Apnhelper", "add operations ");

Contentresolver = context. getcontentresolver ();

Contentvalues =NewContentvalues ();

Contentvalues. Put ("name", APN. getname ());

Contentvalues. Put ("APN", APN. getapn ());

Contentvalues. Put ("MCC", APN. getmcc ());

Contentvalues. Put ("MNC", APN. getmnc ());

Contentvalues. Put ("numeric", APN. getnumeric ());

Contentvalues. Put ("proxy", APN. getproxy ());

Contentvalues. Put ("Port", APN. getport ());

Contentvalues. Put ("authtype", APN. getauthtype ());

Contentvalues. Put ("current", APN. getcurrent ());

Contentvalues. Put ("type", APN. GetType ());

Contentvalues. Put ("user", APN. getuser ());

Contentvalues. Put ("server", APN. getserver ());

Contentvalues. Put ("password", APN. GetPassword ());

Contentvalues. Put ("mmsport", APN. getmmsport ());

Contentvalues. Put ("mmsproxy", APN. getmmsproxy ());

Contentvalues. Put ("mmsc", APN. getmmsc ());

Uri newuri = contentresolver. insert (createuri, contentvalues );

Log.I("Apnhelper", "newuri. tostring ():" + newuri. tostring ());

ReturnNewuri;

}

Delete APN

/**

*
DeletesAPN

*@ ParamID

*@ ReturnSuccessful or not

*/

PublicbooleanDeleteapn (string ID ){

BooleanFlag =True;

APN =
New
APN ();

Contentvalues =NewContentvalues ();

Contentvalues. Put ("current", APN. getcurrent ());

Contentresolver = context. getcontentresolver ();

Try{

Contentresolver. Delete (createuri, "_ id =? ",New
String [] {ID });

Log.I("Apnhelper", "delete operation ");

}Catch(Nullpointerexception e ){

//Todo: Handle exception

E. printstacktrace ();

Flag =False;

}

ReturnFlag;

}

APN sets the current default value

/**

*
Set the default APN

*@ ParamID

*/

PublicintSetdefault (Int
ID ){

Log.I("Apnhelper", "execute settings for current default operations ");

Contentresolver = context. getcontentresolver ();

Contentvalues =NewContentvalues ();

Contentvalues. Put ("apn_id", ID );

IntRows = contentresolver. Update (preferapnuri,
Contentvalues,Null,Null);

Log.I("Apnhelper", "set current value ");

ReturnRows;

}

 


 

About the APN Process

 

 

 


For setting the current default APN, when comparing the two lists, you should save the APN to be set as the current default one to an object, and then when modifying, obtain all visible APN again, traverse them, find the ID of this APN, and set the current default APN.

 

I think this flowchart is incomplete. However, the complete figure is not completed, and the current default setting is not shown above. When this part of the function is completed, most of the difficulties in determining the entire logic are the default setting.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.