这是我用来上传一张照片和一张数据的代码。应用程序不断显示发送对话框,它不会停止。
private void uploadImage() {
String uploadUrl = "http://************.php";
HashMap<String, String> params = new HashMap<>();
params.put("photo_one",imageString(bitmap));
params.put("mobile",mName.getText().toString().trim());
final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Sending Data....");
progressDialog.show();
JsonObjectRequest req = new JsonObjectRequest(uploadUrl, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
progressDialog.dismiss();
String success = (String) response.opt("success");
if (!success.equals("1") )
{
Toast.makeText(getApplicationContext(),"Invalid Username & Password...",Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
}
});
int x=2;// retry count
req.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS * 48, x, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
我使用调试模式检查发生了什么,得到了这个回复。
> req = {JsonObjectRequest@4643} "[ ]
> http://*********.php 0xb5b5014d NORMAL null"
> this = {MainActivity@4174} uploadUrl = "http://***********.php"
> params = {HashMap@4549} size = 2
> progressDialog = {ProgressDialog@4595} req = {JsonObjectRequest@4643} "[]
> http://***********.php 0xb5b5014d NORMAL null" x = 2
答案 0 :(得分:0)
请使用Log查看Json Response。
要连续显示“进度”对话框,请更改以下内容
final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Sending Data....");
progressDialog.show();
到
final ProgressDialog loading = ProgressDialog.show(this,"Sending Data","Please wait...",false,false);