曾经开发过一个小程序,在Android电视机上面开发一个APP,用于显示一些统计图表的信息。最后找来找去基于Android Native开发有AChartEngine现成的组件可用,于是就直接导入jar包,看api文档进行了开发。当然这只是一个客户端程序,数据的来源需要通过服务端程序获得,项目中通过wcf返回json格式的数据。
new Thread(new Runnable() {
@Override
public void run() {
SoapObject soapObject = Util.callWS(nameSpace, methodName2,wsdl, null);
if (soapObject != null) {
String result = soapObject.getProperty(0).toString();
Message msg = new Message();
msg.what = chart2;
msg.obj = result;
handler.sendMessage(msg);
}
}
}).start();
/**
* @param nameSpace
* WS的命名空间
* @param methodName
* WS的方法名
* @param wsdl
* WS的wsdl的完整路径名
* @param params
* WS的方法所需要的参数
* @return SoapObject对象
*/
public static SoapObject callWS(String nameSpace, String methodName,
final String wsdl, Map params) {
final String SOAP_ACTION = nameSpace + "/service/" + methodName;
SoapObject soapObject = new SoapObject(nameSpace, methodName);
if ((params != null) && (!params.isEmpty())) {
Iterator> it = params.entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry) it
.next();
soapObject.addProperty(e.getKey(), e.getValue());
}
}
final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut = soapObject;
envelope.dotNet = true;// 兼容.NET开发的Web Service
envelope.setOutputSoapObject(soapObject);
try {
HttpTransportSE ht = new HttpTransportSE(wsdl);
ht.call(SOAP_ACTION, envelope);
if (envelope.getResponse() != null) {
SoapObject result = (SoapObject) envelope.bodyIn;
ht = null;
return result;
} else {
return null;
}
} catch (Exception e) {
Log.e("error", e.getMessage());
return null;
}
}
String result2 = (String) msg.obj;
int[] colors2 = new int[] { Color.argb(255, 10, 44, 81),Color.argb(255, 182, 34, 49) };
DefaultRenderer renderer2 = SexChart.buildCategoryRenderer(colors2);
// String result =
// "{\"Result_List\":[ { \"SEX\":\"其它\",\"NUM\":\"1\"}, {\"SEX\":\"男\",\"NUM\":\"37\"}, {\"SEX\":\"女\",\"NUM\":\"2\"}]}";
List
public static List