Android obtains the home location of the mobile phone

Source: Internet
Author: User

One requirement is that you need to obtain a mobile phone home location and read a lot on the Internet.CodeI tried a lot of them, but it got stuck when I got to conn. setrequestmethod ("Post") and didn't study the specific problem. Then I checked the WebService that obtained the mobile phone's home location. Address:

Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx? WSDL

I wrote it myself and directly implemented it by calling WebService. The result is OK. It is simpler, but I don't know whether there are any drawbacks.

The following code is used:

Public ClassMobileservice

{

// Namespace

Public Final StaticStringNamespace= "Http://WebXml.com.cn /";

// Soapoption namespace + method name

Public Final StaticStringSoapoption= "Http://WebXml.com.cn/getMobileCodeInfo ";

// Methodname: name of the method to be called

Public Final StaticStringMethodname= "Getmobilecodeinfo ";

// Webserviceurl WebService address

Public Final StaticStringWebserviceurl= "Http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx ";

// Define a soapobject object

PublicSoapobject request =Null;

PublicString getmobileaddress (string phoneno)

{

Request =NewSoapobject (Namespace,Methodname);

Request. addproperty ("mobilecode", phoneno); // Stored Procedure method parameters, parameter names andWebServiceThe order of parameter names must be consistent.

Request. addproperty ("userid ","");

Soapserializationenvelope envelope =NewSoapserializationenvelope (soapenvelope.Ver11);

Envelope. bodyout = request;

Envelope. DOTNET =True; // Specify to call. net

Httptransportse ht =NewHttptransportse (Webserviceurl);

Try

{

Ht. Call (Soapoption, Envelope );

}

Catch(Exception E)

{

E. printstacktrace ();

}

// Obtain data

Try

{

Object result = (object) envelope. getresponse ();

String STR = result. tostring ();

ReturnSTR; // result

}

Catch(Soapfault E)

{

Return Null;

}

}

}

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.