How to log a method in android?

2019-08-19 06:39发布

I am trying to see a log of my publishProgress() call in the Asyncktask class below. To see if it actually is calculating anything while it progresses. As it stands I have a progress dialogue that doesn't update.

 public String strAttachedFile = "";
 public float nTotalSize;
 public float nUploadSize;
public void Send(){

        new Loadvid().execute(); // our call for asynctask
    }

public class Loadvid extends AsyncTask <String,Integer,String>{

            protected void onPreExecute(){
            m_vwProgress.setMax((int)nTotalSize);
            m_vwProgress.setMessage("Uploading, Please wait...");
            m_vwProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                m_vwProgress.show();
            }
        }

protected String doInBackground(String... params) {


            boolean m_bSuccess = true; 
            try
            {

                MultipartEntity me = new MultipartEntity();

                File pFp = new File(strAttachedFile);
                me.addPart("videoFile", new FileBody(pFp, "video/3gpp"));
                httppost.setEntity(me);
                // get the total size of the file
                nTotalSize = pFp.length();

                HttpResponse responsePOST = client.execute(httppost);  
                HttpEntity resEntity = responsePOST.getEntity(); 

                InputStream inputstream = resEntity.getContent();
                StringBuilder stringbuilder = new StringBuilder();
                byte data [] = new byte[512]; 

                while ((len = inputstream.read(data))>0 )
                {
                    StringBuilder result= stringbuilder.append(new String(data, 0, len)); 
                     String s = String.valueOf(result);
                     nUploadSize += len;
                     publishProgress((float)(nTotalSize/nUploadSize));
                      String myString1 = Float.toString((int)nUploadSize);
                     String myString2 = Float.toString((int) nTotalSize);

                     Log.i("Upload SIZEEEEEEEE", myString1);
                     Log.i("Total SIZEEEEEEEE", myString2);

                }
                inputstream.close();

            }catch (Exception e) {
                e.printStackTrace();
                m_bSuccess = false; 
            }

            if(m_bSuccess){
                return "success";//Success

            }

            return null;//failed
        }

protected void onProgressUpdate(Integer... values) {

            if(m_vwProgress !=null){

                m_vwProgress.setProgress(values[0]);
                }
        }


        protected void onPostExecute(String result){

            super.onPostExecute(result);

            if(result==null){
                // failed
                if(m_vwProgress !=null)
                    m_vwProgress.dismiss();

                return;
            }
            else
            {
                //success
                if(m_vwProgress !=null)
                    m_vwProgress.dismiss();
            }
        }

1条回答
SAY GOODBYE
2楼-- · 2019-08-19 07:23

Try to match the variable types between publishProgress & onProgressUpdate parameters

protected void onProgressUpdate(float... values)

or

publishProgress((Integer)(nTotalSize/nUploadSize)*100); 
查看更多
登录 后发表回答