如何登录Android的一个方法是什么? [英] How to log a method in android?

查看:139
本文介绍了如何登录Android的一个方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想看到我的日志publishProgress()调用下面的Asyncktask类。要查看是否它实际上是计算什么,而它的进展。因为它代表我有没有更新进度对话。

 公共字符串strAttachedFile =;
 公众持股量nTotalSize;
 公众持股量nUploadSize;
公共无效的send(){        新Loadvid()执行(); //我们要求的AsyncTask
    }公共类Loadvid扩展的AsyncTask<字符串,整数,字符串> {            在preExecute保护无效(){
            m_vwProgress.setMax((INT)nTotalSize);
            m_vwProgress.setMessage(上传,请稍候...);
            m_vwProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                m_vwProgress.show();
            }
        }保护字符串doInBackground(字符串... PARAMS){
            布尔m_bSuccess = TRUE;
            尝试
            {                MultipartEntity我=新MultipartEntity();                文件=的pFp新文件(strAttachedFile);
                me.addPart(录像档案,新FileBody(PFP,视频/ 3GPP));
                httppost.setEntity(箱);
                //获取文件的总大小
                nTotalSize = pFp.length();                HTT presponse responsePOST = client.execute(httppost);
                HttpEntity resEntity = responsePOST.getEntity();                为InputStream的InputStream = resEntity.getContent();
                StringBuilder的StringBuilder的=新的StringBuilder();
                字节的数据[] =新的字节[512];                而((LEN = inputstream.read(数据))大于0)
                {
                    StringBuilder的结果= stringbuilder.append(新的String(数据,0,LEN));
                     字符串s =将String.valueOf(结果);
                     nUploadSize + = LEN;
                     publishProgress((浮点)(nTotalSize / nUploadSize));
                      字符串myString1 = Float.toString((INT)nUploadSize);
                     字符串myString2 = Float.toString((INT)nTotalSize);                     Log.i(上传SIZEEEEEEEE,myString1);
                     Log.i(总SIZEEEEEEEE,myString2);                }
                inputstream.close();            }赶上(例外五){
                e.printStackTrace();
                m_bSuccess = FALSE;
            }            如果(m_bSuccess){
                返回成功; //成功            }            返回null; //失败
        }保护无效onProgressUpdate(整数...值){            如果(m_vwProgress!= NULL){                m_vwProgress.setProgress(值[0]);
                }
        }
        保护无效onPostExecute(字符串结果){            super.onPostExecute(结果);            如果(结果== NULL){
                //失败
                如果(m_vwProgress!= NULL)
                    m_vwProgress.dismiss();                返回;
            }
            其他
            {
                //成功
                如果(m_vwProgress!= NULL)
                    m_vwProgress.dismiss();
            }
        }


解决方案

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

 保护无效onProgressUpdate(浮动...值)

  publishProgress((整数)(nTotalSize / nUploadSize)* 100);

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();
            }
        }

解决方案

Try to match the variable types between publishProgress & onProgressUpdate parameters

protected void onProgressUpdate(float... values)

or

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

这篇关于如何登录Android的一个方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆