通过肥皂进行缓慢的图像更新

时间:2018-07-23 12:17:01

标签: android-studio soap ksoap2

我正在使用肥皂服务将图像上载到服务器,但是它工作正常,但是图像上载速度非常慢。 我的代码是这样的: getImage同步返回一个以图像和图像名称为键的搭扣。

class SyncFinalImagesToServer extends AsyncTask<String, Void, String> {

    Context context;
    String imageName = "", finalImageName = "";
    private Object rq;
    String finalValue = "";
    private ProgressDialog progressDialog;

    public SyncFinalImagesToServer() {

    }

    @Override
    protected void onPreExecute() {

        progressDialog = new ProgressDialog(context);
        progressDialog.setMax(100); // Progress Dialog Max Value
        progressDialog.setMessage("Loading..."); // Setting Message
        progressDialog.setTitle("Image"); // Setting Title
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        super.onPreExecute();
    }

    @Override
    protected void onPostExecute(String s) {
        progressDialog.setProgress(100);
        progressDialog.dismiss();
        super.onPostExecute(s);
    }

    @Override
    protected String doInBackground(String... imageData) {
        String result = "";
        try {
            StrictMode.ThreadPolicy policy1 = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy1);
            finalImageName = imageData[0];
            imageName = imageData[1];
            StrictMode.ThreadPolicy policy2 = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy2);
            if (!finalImageName.toString().equalsIgnoreCase("")) {
                                   progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

                result = syncFSEData("uploadFinalImagesSMRD");
            }

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return result;
    }

    public SyncFinalImagesToServer(Context ctx) {
        this.context = ctx;
    }


    public String syncFSEData(String methName) throws IOException, JSONException {


        String NAMESPACE = "http://tempuri.org/";
        String URL = "url";
        String SOAP_ACTION = "http://tempuri.org/";
        String resTxt = null;
        SoapObject request = new SoapObject(NAMESPACE, methName);

        PropertyInfo user = new PropertyInfo();
        user.setName("data");
        user.setValue(finalImageName);
        user.setType(String.class);
        request.addProperty(user);

        PropertyInfo user1 = new PropertyInfo();
        user1.setName("fileName");
        user1.setValue(imageName);
        user1.setType(String.class);
        request.addProperty(user1);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

        envelope.dotNet = true;
        envelope.implicitTypes = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {
            androidHttpTransport.call(SOAP_ACTION + methName, envelope);
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            resTxt = response.toString();
            if (resTxt.contains("Success")) {

                String[] imageNameArray = resTxt.split("#");
                String image = imageNameArray[0].toString();
                DatabaseHelper db = new DatabaseHelper(context);
                long result = db.updateSyncCompletedSMRDImagesFinal(image);
                if (result != -1) {
//                    progressDialog.dismiss();

                    //DatabaseHelper db= new DatabaseHelper(HomeActivity.this);
//                    db.getImagesToSync();

                    Toast.makeText(context, "FSE Data Sync Completed Successfully", Toast.LENGTH_LONG).show();
                }
                else {
                    Toast.makeText(context, "FSE Data Sync Completed Successfully", Toast.LENGTH_LONG).show();
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
            resTxt = "Error";
        }
        return resTxt.toString();
    }
}

0 个答案:

没有答案