各位it精英们,请问一下,我开发了一个天气与报的android软件,它是通过解析WEBSERVICE来获取天气情况的,在模拟器上可以访问,但是用手机时便不可以访问,请问如何使用GPRS访问webservice来获取天气预报啊?
解决方案 »
- Apache的HttpPut方法
- 求翻译.。。。。。。。
- 求助:为甚么run confirguations只有4.0.3版本
- 【教程】利用Android TabHost+ActivityGroup+Broadcast实现iPhone的底部菜单
- 请问framework的AndroidManifest.xml什么时候被PackageManagerService扫描的?
- 急等解答 NDK 环境编译提示找不到 AttachCurrentThread
- 请问android如何让父窗口上背景的长宽 自动适应 和它上面子窗口所占长宽的大小一样呢?
- 【新手未入门】unfortunately 程序名 has stopped提示(有日志有代码)
- 有没有做android4.4.2 settings的,求交流呀!
- 请问android 怎么实现ZMQ通讯
- Surfaceview lockCanvas 锁特定rect的问题
- 列表问题,不显示
* 获取web services内容
*
* @param url
* @param params
* @return
*************************************/
public static String GetResponse(String method,
List<BasicNameValuePair> params) { try {
String url = WSUrl;
SoapObject request = new SoapObject(namespace, method);
for (int i = 0, len = params.size(); i < len; i++) {
request.addProperty(params.get(i).getName(), params.get(i)
.getValue());
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
// 设置10秒超时
int timeout = 10000; // set timeout 15s
MyAndroidHttpTransport transport = new MyAndroidHttpTransport(url,
timeout);
// AndroidHttpTransport androidHttpTransport = new
// AndroidHttpTransport(
// url);
// androidHttpTransport.call(namespace + method, envelope); transport.call(namespace + method, envelope); SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
return result.toString();
} catch (Exception e) {
return "Error:calling the web services error";
}
}
public class MyAndroidHttpTransport extends HttpTransportSE { private int timeout = 30000; // 默认超时时间为30s public MyAndroidHttpTransport(String url) {
super(url);
} public MyAndroidHttpTransport(String url, int timeout) {
super(url);
this.timeout = timeout;
} // 设置调用超时方法,默认
protected ServiceConnection getServiceConnection(String url)
throws IOException {
ServiceConnectionSE serviceConnection = new ServiceConnectionSE(url);
serviceConnection.setConnectionTimeOut(timeout);
return new ServiceConnectionSE(url);
}
}
我这边正常运行,你参考下看看。或者是你检查下有没有给权限。