Hello android Forum brethren. I am trying to upload a video to an api and I was wondering how you show a progress bar show and also dismiss it when an upload has finished? Also, while were at it, do you see anything wrong with my pattern.compile for my edit boxes?
But it doesn't work. When i click on the button to send, it shows the handler for 2 seconds then brings up an error close.
Error log tells me that i have my errors caused at the
Matcher matcher = keys.matcher((CharSequence) etxt_user);
@ "do in background"
and somewhere in my onPrexecute.
What am I doing wrong, help please!
Code:
public class Loadvid extends AsyncTask <Object,Integer,String>{
EditText etxt_user = (EditText) findViewById(R.id.user_email);
EditText etxt_pass = (EditText) findViewById(R.id.friend_email);
protected void onPreExecute(){
dialog = new ProgressDialog(share.this);
dialog.show();
super.onPreExecute();
}
@Override
protected String doInBackground(Object... params) {
if(etxt_user.equals("")||etxt_pass.equals("")){
dialog.dismiss();
Alert.setMessage("Please fill in the Blanks");
Alert.show();
}
else{
//make sure the edit boxes have some information before proceeding
Pattern keys= 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 = keys.matcher((CharSequence) etxt_user);
Matcher matcher1 = keys.matcher((CharSequence) etxt_pass);
if(!matcher.matches()|| !matcher1.matches())
{
dialog.dismiss();
Alert.setMessage("Wrong email address.");
Alert.show();
}
}
//implement the httppost.
try
{
MultipartEntity me = new MultipartEntity();
me.addPart("file", new FileBody(new File("/")));
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();}
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result){
super.onPostExecute(result);
dialog.dismiss();
Alert.setMessage("Upload Succeeded");
Alert.show();
Intent intent = new Intent("com...");
startActivity(intent);
}
}
Error log tells me that i have my errors caused at the
Matcher matcher = keys.matcher((CharSequence) etxt_user);
@ "do in background"
and somewhere in my onPrexecute.
What am I doing wrong, help please!