diff --git a/android-post-json/AndroidManifest.xml b/android-post-json/AndroidManifest.xml
new file mode 100644
index 0000000..fed38ce
--- /dev/null
+++ b/android-post-json/AndroidManifest.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android-post-json/ic_launcher-web.png b/android-post-json/ic_launcher-web.png
new file mode 100644
index 0000000..a18cbb4
Binary files /dev/null and b/android-post-json/ic_launcher-web.png differ
diff --git a/android-post-json/res/drawable-hdpi/ic_launcher.png b/android-post-json/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..288b665
Binary files /dev/null and b/android-post-json/res/drawable-hdpi/ic_launcher.png differ
diff --git a/android-post-json/res/layout/activity_main.xml b/android-post-json/res/layout/activity_main.xml
new file mode 100644
index 0000000..921cdeb
--- /dev/null
+++ b/android-post-json/res/layout/activity_main.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android-post-json/res/menu/main.xml b/android-post-json/res/menu/main.xml
new file mode 100644
index 0000000..c002028
--- /dev/null
+++ b/android-post-json/res/menu/main.xml
@@ -0,0 +1,9 @@
+
diff --git a/android-post-json/res/values/dimens.xml b/android-post-json/res/values/dimens.xml
new file mode 100644
index 0000000..55c1e59
--- /dev/null
+++ b/android-post-json/res/values/dimens.xml
@@ -0,0 +1,7 @@
+
+
+
+ 16dp
+ 16dp
+
+
diff --git a/android-post-json/res/values/strings.xml b/android-post-json/res/values/strings.xml
new file mode 100644
index 0000000..2a38769
--- /dev/null
+++ b/android-post-json/res/values/strings.xml
@@ -0,0 +1,8 @@
+
+
+
+ POST JSON
+ Settings
+ Hello world!
+
+
diff --git a/android-post-json/res/values/styles.xml b/android-post-json/res/values/styles.xml
new file mode 100644
index 0000000..6ce89c7
--- /dev/null
+++ b/android-post-json/res/values/styles.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
diff --git a/android-post-json/src/com/hmkcode/android/MainActivity.java b/android-post-json/src/com/hmkcode/android/MainActivity.java
new file mode 100644
index 0000000..a68d5f4
--- /dev/null
+++ b/android-post-json/src/com/hmkcode/android/MainActivity.java
@@ -0,0 +1,186 @@
+package com.hmkcode.android;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.json.JSONObject;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.app.Activity;
+import com.hmkcode.android.vo.Person;
+
+public class MainActivity extends Activity implements OnClickListener {
+
+ TextView tvIsConnected;
+ EditText etName,etCountry,etTwitter;
+ Button btnPost;
+
+ Person person;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ // get reference to the views
+ tvIsConnected = (TextView) findViewById(R.id.tvIsConnected);
+ etName = (EditText) findViewById(R.id.etName);
+ etCountry = (EditText) findViewById(R.id.etCountry);
+ etTwitter = (EditText) findViewById(R.id.etTwitter);
+ btnPost = (Button) findViewById(R.id.btnPost);
+
+ // check if you are connected or not
+ if(isConnected()){
+ tvIsConnected.setBackgroundColor(0xFF00CC00);
+ tvIsConnected.setText("You are conncted");
+ }
+ else{
+ tvIsConnected.setText("You are NOT conncted");
+ }
+
+ // add click listener to Button "POST"
+ btnPost.setOnClickListener(this);
+
+
+ }
+
+ public static String POST(String url, Person person){
+ InputStream inputStream = null;
+ String result = "";
+ try {
+
+ // 1. create HttpClient
+ HttpClient httpclient = new DefaultHttpClient();
+
+ // 2. make POST request to the given URL
+ HttpPost httpPost = new HttpPost(url);
+
+ String json = "";
+
+
+ // 3. build jsonObject
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.accumulate("name", person.getName());
+ jsonObject.accumulate("country", person.getCountry());
+ jsonObject.accumulate("twitter", person.getTwitter());
+
+ // 4. convert JSONObject to JSON to String
+ json = jsonObject.toString();
+
+
+ // ** Alternative way to convert Person object to JSON string usin Jackson Lib
+ // ObjectMapper mapper = new ObjectMapper();
+ // json = mapper.writeValueAsString(person);
+
+ // 5. set json to StringEntity
+ StringEntity se = new StringEntity(json);
+
+ // 6. set httpPost Entity
+ httpPost.setEntity(se);
+
+ // 7. Set some headers to inform server about the type of the content
+ httpPost.setHeader("Accept", "application/json");
+ httpPost.setHeader("Content-type", "application/json");
+
+ // 8. Execute POST request to the given URL
+ HttpResponse httpResponse = httpclient.execute(httpPost);
+
+ // 9. receive response as inputStream
+ inputStream = httpResponse.getEntity().getContent();
+
+
+ // 10. convert inputstream to string
+ if(inputStream != null)
+ result = convertInputStreamToString(inputStream);
+ else
+ result = "Did not work!";
+
+ } catch (Exception e) {
+ Log.d("InputStream", e.getLocalizedMessage());
+ }
+
+ // 11. return result
+ return result;
+ }
+
+ @Override
+ public void onClick(View view) {
+
+ switch(view.getId()){
+ case R.id.btnPost:
+ if(!validate())
+ Toast.makeText(getBaseContext(), "Enter some data!", Toast.LENGTH_LONG).show();
+ // call AsynTask to perform network operation on separate thread
+ new HttpAsyncTask().execute("http://hmkcode.appspot.com/jsonservlet");
+ break;
+ }
+
+ }
+
+ public boolean isConnected(){
+ ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
+ if (networkInfo != null && networkInfo.isConnected())
+ return true;
+ else
+ return false;
+ }
+
+ private class HttpAsyncTask extends AsyncTask {
+ @Override
+ protected String doInBackground(String... urls) {
+
+ person = new Person();
+ person.setName(etName.getText().toString());
+ person.setCountry(etCountry.getText().toString());
+ person.setTwitter(etTwitter.getText().toString());
+
+ return POST(urls[0],person);
+ }
+ // onPostExecute displays the results of the AsyncTask.
+ @Override
+ protected void onPostExecute(String result) {
+ Toast.makeText(getBaseContext(), "Data Sent!", Toast.LENGTH_LONG).show();
+ }
+ }
+
+
+ private boolean validate(){
+ if(etName.getText().toString().trim().equals(""))
+ return false;
+ else if(etCountry.getText().toString().trim().equals(""))
+ return false;
+ else if(etTwitter.getText().toString().trim().equals(""))
+ return false;
+ else
+ return true;
+ }
+ private static String convertInputStreamToString(InputStream inputStream) throws IOException{
+ BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
+ String line = "";
+ String result = "";
+ while((line = bufferedReader.readLine()) != null)
+ result += line;
+
+ inputStream.close();
+ return result;
+
+ }
+
+
+}
diff --git a/android-post-json/src/com/hmkcode/android/vo/Person.java b/android-post-json/src/com/hmkcode/android/vo/Person.java
new file mode 100644
index 0000000..ec39e4e
--- /dev/null
+++ b/android-post-json/src/com/hmkcode/android/vo/Person.java
@@ -0,0 +1,40 @@
+package com.hmkcode.android.vo;
+
+public class Person {
+
+ private String name;
+ private String country;
+ private String twitter;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String getTwitter() {
+ return twitter;
+ }
+
+ public void setTwitter(String twitter) {
+ this.twitter = twitter;
+ }
+
+ @Override
+ public String toString() {
+ return "Person [name=" + name + ", country=" + country + ", twitter="
+ + twitter + "]";
+ }
+
+
+}