我通过从图库中选择图像或使用 android 相机捕获图像将图像上传到 Web 服务器。
我需要在通知栏中显示进度。我看到 Facebook 应用程序是这样做的。有没有办法查出上传了多少?
我将图像上传到服务器的代码是:
public void uploadImage() {
final Toast toast = Toast.makeText(this, "Image uploaded successfully",
Toast.LENGTH_SHORT);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Upload");
builder.setMessage("Do you want to upload the captured picture?");
builder.setIcon(R.drawable.icon);
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
testWebService(Bitmap bmp)
finish();
toast.show();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void testWebService(Bitmap bmp) {
MarshalBase64 marshal = new MarshalBase64();
ByteArrayOutputStream out = new ByteArrayOutputStream();
bmp.compress(CompressFormat.PNG, 100, out);
byte[] raw = out.toByteArray();
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
OPERATION_NAME);
request.addProperty("image", raw);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
marshal.register(envelope);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
httpTransport.call(SOAP_ACTION, envelope);
Object response = envelope.getResponse();
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
有没有办法查出上传了多少?