如何在android中记录方法?

时间:2012-03-07 13:24:23

标签: android android-asynctask logging

我试图在下面的Asyncktask类中看到我的publishProgress()调用的日志。看它实际上是在计算任何进展的时候。目前我有一个没有更新的进度对话。

 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 个答案:

答案 0 :(得分:0)

尝试匹配publishProgress&amp;之间的变量类型onProgressUpdate个参数

protected void onProgressUpdate(float... values)

publishProgress((Integer)(nTotalSize/nUploadSize)*100);