Set and obtain the mobile phone number for Android APN

Source: Internet
Author: User

Currently, I work for China Telecom and only work for China Telecom. Therefore, the list only contains China Telecom's APN information.

Java code

/**

* China Telecom APN list

* @ Author wudongdong

*

*/

Public class apnnet {

Public static string ctwap = "ctwap ";

Public static string ctnet = "ctnet ";

}

/**

* China Telecom APN list

* @ Author wudongdong

*

*/

Public class apnnet {

Public static string ctwap = "ctwap ";

Public static string ctnet = "ctnet ";

} Obtain the APN type

Java code

/**

* Obtain the APN type

* @ Author wudongdong

*

*/

Public class apnutil {

Private Static URI preferred_apn_uri = URI

. Parse ("content: // telephony/carriers/preferapn ");

/**

* Get apntype

* @ Param Context

* @ Return

*/

Public static string getapntype (context ){

String apntype = "nomatch ";

Cursor c = context. getcontentresolver (). Query (preferred_apn_uri,

Null, null );

C. movetofirst ();

String user = C. getstring (C. getcolumnindex ("user "));

If (user. startswith (apnnet. ctnet )){

Apntype = apnnet. ctnet;

} Else if (user. startswith (apnnet. ctwap )){

Apntype = apnnet. ctwap;

}

Return apntype;

}

}

/**

* Obtain the APN type

* @ Author wudongdong

*

*/

Public class apnutil {

Private Static URI preferred_apn_uri = URI

. Parse ("content: // telephony/carriers/preferapn ");

/**

* Get apntype

* @ Param Context

* @ Return

*/

Public static string getapntype (context ){

String apntype = "nomatch ";

Cursor c = context. getcontentresolver (). Query (preferred_apn_uri,

Null, null );

C. movetofirst ();

String user = C. getstring (C. getcolumnindex ("user "));

If (user. startswith (apnnet. ctnet )){

Apntype = apnnet. ctnet;

} Else if (user. startswith (apnnet. ctwap )){

Apntype = apnnet. ctwap;

}

Return apntype;

}

}

If you obtain the mobile phone number, you can transmit the imsi code to the specified interface. The interface address is not convenient.

However, it can be disclosed that ctwap is required, which is also the reason for determining the APN type.

If you find that many applications cannot connect to the Internet if you use an APN proxy, let's introduce the network proxy information configured with the APN.

Java code

Cursor c = context. getcontentresolver (). Query (preferred_apn_uri,

Null, null );

C. movetofirst ();

String proxy = C. getstring (C. getcolumnindex ("proxy "));

If (! "". Equals (proxy) & proxy! = NULL ){

Properties prop = system. getproperties ();

System. getproperties (). Put ("proxyset", "true ");

Prop. setproperty ("HTTP. proxyhost", C. getstring (C

. Getcolumnindex ("proxy ")));

Prop. setproperty ("HTTP. proxyport", C. getstring (C

. Getcolumnindex ("Port ")));

String authentication = C. getstring (C. getcolumnindex ("user "))

+ ":" + C. getstring (C. getcolumnindex ("password "));

String encodedlogin = base64.encode (authentication );

UC. setrequestproperty ("proxy-Authorization", "Basic"

+ Encodedlogin );

}

C. Close ();

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.