开发者

Progress dialogue and toast failing on sending HTTP Post through MultipartEntity

开发者 https://www.devze.com 2023-03-24 11:40 出处:网络
I am still relatively an amateur at android programming. I have a very annoying issue. When i click send in my class it doesn\'t show a progress dialogue and it also ignores my validations that I have

I am still relatively an amateur at android programming. I have a very annoying issue. When i click send in my class it doesn't show a progress dialogue and it also ignores my validations that I have for 2 edit text buttons that I have. My code might be very messy and unorganized. i apologize in advance.

What i need to do is show my progress dialogue running and on the end of the Handler get it to dismiss. Also I need my toast to show and the class to stop working.

    public class share extends Activity {
    ProgressDialog dialog;
    DefaultHttpClient client = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://api...");


    @Override

    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.send);
    Button Deliver;

    Deliver = (Button) findViewById (R.id.Send);
    Deliver.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
      final ProgressDialog dialog = ProgressDialog.show(share.this, "","Uploading...", true);
      dialog.show();
      Handler handler = new Handler();
      handler.post(new Runnable() {
      public void run() {

    EditText etxt_user = (EditText) findViewById(R.id.user_email);
      EditText etxt_pass = (EditText) findViewById(R.id.friend_email);

    if(file == null){

    Toast display = Toast.makeText(share.this, "There are no videos to send", Toast.LENGTH_SHORT);
 display.setGravity(Gravity.BOTTOM|Gravity.LEFT, 0, 0); 
 display.show();

    startActivity(new Intent("android.main.SHARE"));

                         }

    else{

     Pattern pattern= Pattern.compile(
     "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
    "\\@" +
    "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
     "(" +"\\." +  "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +")+"
    );

     Matcher matcher=pattern.matcher(etxt_user.getText().toString());// match the contents of the first edit text
    Matcher matcher1=pattern.matcher(etxt_pass.getText().toString());

     if (!matcher.matches()&&(etxt_user.getText().toString()==null))
                          {
     Toast display1 = Toast.makeText(share.this, "Please enter correct email address", Toast.LENGTH_SHORT);
    display1.show();
    startActivity(new Intent("com..SHARE"));


     }
    else
        {
            //proceed with program                
        }

    if (!matcher1.matches()&&!(etxt_pass.getText().toString()==null)){

    Toast display2= Toast.makeText(share.this, "You entered wrong email Format in the second box", Toast.LENGTH_LONG);
 display2.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);                         
 startActivity(new Intent("com.apapa.vrsixty.SHARE"));                        
    }
    else
    {
          //proceed
     }

    try{

     MultipartEntity me = new MultipartEntity();

    me.addPart("file", new FileBody(new File("/sdcard/videocapture_example.H264")));

    me.addPart("userEmail", new StringBody(etxt_user.getText().toString())); 
     me.addPart("friendEmail", new StringBody(etxt_pass.getText().toString()));

     httppost.setEntity(me);

    HttpResponse responsePOST = client.execute(httppost);  
     HttpEntity resEntity = responsePOST.getEntity(); 
    InputStream inputstream = resEntity.getContent();
    BufferedReader buffered = new BufferedReader(new InputStreamReader(inputstream));
        StringBuilder stringbuilder = new StringBuilder();
        String currentline = null; 
        while ((currentline = buffered.readLine()) != null) { 
         stringbuilder.append(currentline + "\n"); 
        String result = stringbuilder.toString(); 
        Log.v("HTTP UPLOAD REQUEST",result); 
        inputstream.close();  } }
   开发者_JS百科     catch (Exception e) {
        e.printStackTrace();
                }               
                         }dialog.dismiss();
                }
            });
                }
            });

When I am done with this and I press send, it gives me a black screen with no progress dialogue and even if I have validations in place for my edit text or if there is no file to send, it just runs the program without stopping it and showing a toast. Thank you in advance guys


Well it looks like your httppost is sending it to "http://", which is not exactly a valid address, which is part of your problem.

Also: Is that code verbatim? There is no way it should run. at the very beginning you have this line

new HttpPost("http://"");

You have two quotes at the end, which effectively makes everything after the second quote a string until it runs into a closing quote.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号