Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is my code snippet, Hope this helps :</p> <pre><code>private class AsyncTask1 extends AsyncTask&lt;Void, Void, String&gt;{ @Override protected String doInBackground(Void... params) { boolean response = false; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); FileBody bin = new FileBody(new File("temp")); File tempImg = new File("sdcard/signature.jpg"); if(tempImg.exists()) { checkimgfile=checkimgfile+"LPA"+tempImg; bin = new FileBody(tempImg, "image/jpg"); reqEntity.addPart("txt_sign_lpa", bin); reqEntity.addPart("count_lpa",new StringBody("1")); } else { reqEntity.addPart("count_lpa",new StringBody("0")); } FileBody bin1 = new FileBody(new File("temp")); File tempImg1 = new File("sdcard/signature2.jpg"); if(tempImg1.exists()) { checkimgfile=checkimgfile+"subject"+tempImg1; bin1 = new FileBody(tempImg1, "image/jpg"); reqEntity.addPart("txt_sign", bin1); reqEntity.addPart("count_subject",new StringBody("1")); } reqEntity.addPart("count",new StringBody("0")); reqEntity.addPart("name",new StringBody("Shaili")); reqEntity.addPart("age",new StringBody("47")); try { ConnectivityManager cm = (ConnectivityManager)getBaseContext().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if(activeNetwork!=null &amp;&amp; activeNetwork.isAvailable() &amp;&amp; activeNetwork.isConnected()) { String xml = ""; HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 100000); HttpConnectionParams.setSoTimeout(httpParameters, 100000); final HttpClient httpclient = new DefaultHttpClient(httpParameters); final HttpPost httppost = new HttpPost("https://www.xyz.com/abc.php");//url where you want to post your data. httppost.setParams(httpParameters); httppost.setEntity(reqEntity); httppost.addHeader("Accept", "text/html"); httppost.addHeader("Host", "www.xyz.com"); httppost.addHeader("User-Agent", "Android "); HttpResponse response1 = null; String errMessage = "Error"; try { response1 = httpclient.execute(httppost); final HttpEntity resEntity = response1.getEntity(); InputStream content = resEntity.getContent(); BufferedReader b = new BufferedReader(new InputStreamReader( content)); xml = XmlParser.getTrimmedResponse(b); if (response1 != null){ if(Integer.toString(response1.getStatusLine().getStatusCode()).equals("200")){ return "success"; } } } catch (Exception e) { e.printStackTrace(); errorstring=errorstring+e.getLocalizedMessage(); errMessage = "Network error"; return errMessage; } } else if(activeNetwork==null) { return "Available"; } } catch(Exception e) { Toast.makeText(getBaseContext(), "Network Connection not available", 1).show(); progressDialog.dismiss(); } } catch (Exception e) { errorstring=errorstring+e.getLocalizedMessage(); return "Network error"; } return "abc"; } protected void onPostExecute(String result) { //do your stuff } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload