I'm doing a job for the school but I'm having problems with the images. I get System.Byte [] from my web service and I've tried several solutions and I can't convert to bitmap and add my ImageView. In my database the column "Image" appears . Can someone help me? thanks
Here is my android code.
private String NAMESPACE = "http://tempuri.org/";
private String URL = "http://X.X.X.X/ProjetoFinal/WSGestao.asmx?WSDL";
private String METHOD_NAME = "List_Images";
private String SOAP_ACTION = "http://tempuri.org/List_Images";
private String[] List;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
new MyAsyncTask().execute();
}
private class MyAsyncTask extends AsyncTask<Void,Void,String[]> {
protected String[] doInBackground(Void... strings) {
//connection to the web service
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
//Fetch the server's response and add the list
List = new String[response.getPropertyCount()];
for (int i = 0; i < response.getPropertyCount(); i++) {
List[i] = response.getProperty(i).toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return List;
}
@Override
protected void onPostExecute(String[] result) {
super.onPostExecute(result);
//convert to Bitmap
}
}
The web service sends:
<ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
<string>System.Byte[]</string>
</ArrayOfString>
public static void setImageViewWithByteArray(ImageView view, Byte[] data) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
view.setImageBitmap(bitmap);
}
Use this code to display byte [] on imageView