Onelong

分享知识,与你一起进步......
RSS icon Home icon
  • android调用ksoap的天气预报

    post by onelong / 2011-1-2 6:31 Sunday [android]

    首先我想说的是,这个源码不是我自己写的,那是从网上下载来的!!天气数据的来源是http://WebXml.com.cn/

    我知道网上有很多例子,但是我还觉得这个例子比较简单,核心代码还是和上一篇文中的一样。这次只要是把整一个工程文件上传来!

     

     /*

         * 核心代码

         * */

        public void getWeather(String cityName) {

    try {

    SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);

     

    rpc.addProperty("theCityName", cityName);

     

    AndroidHttpTransport ht = new AndroidHttpTransport(URL);

    ht.debug = false;

     

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

     

    envelope.bodyOut = rpc;

    envelope.dotNet = true;

    envelope.setOutputSoapObject(rpc);

     

    ht.call(SOAP_ACTION, envelope);

     

    SoapObject result = (SoapObject) envelope.bodyIn;

    SoapObject detail = (SoapObject) result.getProperty("getWeatherbyCityNameResult");

     

    parseWeather(detail);

    } catch (Exception e) {

    Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();

    }

    }

    工程文件见附件,工程都是在linux下生成的,所以在windows下可能会乱码!!

    附件下载:
    Weather.zip 504.22KB

    引用地址:
     

    我要评论