I am capturing an image and saving it to SD card every thing is ok. But I need to send this image may be as a string or base64 or utf-8 with some other data like username,password.Just tell me how to process that data variable and send it to server using http request
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFileDir = getDir();
if (!pictureFileDir.exists() && !pictureFileDir.mkdirs())
{
Toast.makeText(context, "Can't create directory to save image.",Toast.LENGTH_LONG).show();
return;
}
String photoFile = "MyPicture.jpg";
String filename = pictureFileDir.getPath() + File.separator + photoFile;
File pictureFile = new File(filename);
//Need to send this data to server
data.toString();
try
{
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
Toast.makeText(context, "New Image saved:" + photoFile,Toast.LENGTH_LONG).show();
}
catch (Exception error)
{
Toast.makeText(context, "Image could not be saved.",Toast.LENGTH_LONG).show();
}
public void postData(String emailId,String passwrd) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://XXXXAAAA.com/login");
try {
// Data that I am sending
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("mb_code", emailId));
nameValuePairs.add(new BasicNameValuePair("pwd", passwrd));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
responseBody = EntityUtils.toString(response.getEntity());
Log.d("result", responseBody);
}
catch (Throwable t ) {
//Toast.makeText( getApplicationContext(),""+t,Toast.LENGTH_LONG).show();
Log.d("Error Time of Login",t+"");
}
}
}