아래의 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();
}
}
사이의 변수 유형에 맞게 :'로그를 호출합니다. (tag, message);'. 메시지는'LogCat' 창에 나타나야합니다. 만약 당신이 그 메소드 호출에 도달하지 못하거나'message' 매개 변수가 비어 있다면. –
Jave
내가 이것을 추가하면 @Jave : Log.i ("Show progresssss", "publishProgress()"); 오류가 발생하여 실행되지 않습니다. 그게 왜 내가 publishProgress()를 보여줄지 알아 내려고하는 이유입니다. Thansk 당신의 대답을위한 방법 – user875139