写好的Demo中可以,但是移到项目上就出问题了,Debug发现无法进入回调,文件也没有上传成功,也没有报错。。。。
private class UploadFilesTask extends AsyncTask<String, Integer, String>
{
protected void onPreExecute()
{
dialog = new Dialog(BackupActivity.this, R.style.theme_dialog_alert);
dialog.setContentView(R.layout.window_layout);
dialog.setCancelable(true);
dialog.show();
}
protected String doInBackground(String... bucket)
{
nu = new NetUtils();
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("bucket", bucket[0]));
params.add(new BasicNameValuePair("key", key));
String response = nu.getUptoken(params);
if (response.equals(""))
{
msg.what = 0;
msg.obj = "备份失败,请检查是否有网络连接";
return null;
}
JSONObject jObj = JSON.parseObject(response);
auth = new Authorizer();
auth.setUploadToken(jObj.getString("uptoken"));
boolean isUpload = nu.doUpload(BackupActivity.this, auth, key, Uri.parse(C.LOCAL_PATH + vfile + ".vcf"));
if (!isUpload)
{
msg.obj = "备份失败,请重新上传!";
return null;
}
msg.obj = "备份成功!";
return null;
}
protected void onProgressUpdate(Integer... progress)
{
Log.e("BackupActivity", progress[0] + "");
}
protected void onPostExecute(String result)
{
dialog.dismiss();
}
}
doUpload方法代码片段:
/**
* 普通上传文件
* @param uri 待上传文件的URI地址
* @param auth
*/
public boolean doUpload(Context context, Authorizer auth, String key, Uri uri)
{
PutExtra extra = new PutExtra();
extra.params = new HashMap<String, String>();
// 返回 UploadTaskExecutor ,可执行cancel,见 MyResumableActivity
IO.putFile(context, auth, key, uri, extra, new CallBack()
{
@Override
public void onProcess(long current, long total)
{
}
@Override
public void onSuccess(UploadCallRet ret)
{
isUpload = true;
}
@Override
public void onFailure(CallRet ret)
{
isUpload = false;
Log.e(NetUtils, ret.toString());
}
});
return isUpload;
}
调用方法:
new UploadFilesTask().execute("pocketanti-vcf");
你没有上传成功肯定是不会回调的,你有没有上传的请求的reqid。