Working With ION In Android

//
//Android Code
//


//Manifest
<uses-permission android:name="android.permission.INTERNET"/>

//build.gradle (Module:app)
dependencies {
    ...
    compile group: 'com.koushikdutta.ion', name: 'ion', version: '2.1.6'
}

//MainActivity.java
    public void SubmitData(View view){

        JsonObject json = new JsonObject();
        json.addProperty("foo", "bar");
        json.addProperty("bar", "foo");
        try
        {
            Ion.with(getApplicationContext())
                    .load("http://182.160.99.115:1012/Home/SubmitData")
                    .setJsonObjectBody(json)
                    .asJsonObject()
                    .setCallback(new FutureCallback<JsonObject>() {
                        @Override
                        public void onCompleted(Exception e, JsonObject result) {

                         String ServerSaid =  result.get("serversay").getAsString();

                            Toast.makeText(getApplicationContext(),ServerSaid,Toast.LENGTH_LONG).show();
                        }
                    });

        }
        catch (Exception ex ){
            Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
        }
    }
//
//ASP.NET MVC Code
//


namespace WorkingWithIon.Controllers
{
    public class HomeController : Controller
    {     
        public JsonResult SubmitData(string foo, string bar)
        {
            return Json(new{serversay=foo + " and " + bar}, JsonRequestBehavior.AllowGet);
        }
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s