Unable To Insert Into Azure Via Android Application
im doing a login register for my application and i have to integrate them together with microsoft azure. However, despite after following the tutorial given by microsoft azure, i s
Solution 1:
Here is an code snippet , hoping it will help you.
1)An function which carries the http get service
private String SendDataFromAndroidDevice() {
Stringresult="";
try {
HttpClienthttpclient=newDefaultHttpClient();
HttpGetgetMethod=newHttpGet("your url + data appended");
BufferedReaderin=null;
BasicHttpResponsehttpResponse= (BasicHttpResponse) httpclient
.execute(getMethod);
in = newBufferedReader(newInputStreamReader(httpResponse
.getEntity().getContent()));
StringBuffersb=newStringBuffer("");
Stringline="";
while ((line = in.readLine()) != null) {
sb.append(line);
}
in.close();
result = sb.toString();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
2) An Class which extends AsyncTask
privateclassHTTPdemoextendsAsyncTask<String, Void, String> {
@OverrideprotectedvoidonPreExecute() {}
@OverrideprotectedStringdoInBackground(String... params) {
String result = SendDataFromAndroidDevice();
return result;
}
@OverrideprotectedvoidonProgressUpdate(Void... values) {}
@OverrideprotectedvoidonPostExecute(String result) {
if (result != null && !result.equals("")) {
try {
JSONObject resObject = newJSONObject(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
3) Inside your onCreate method
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView("your layout");
if ("check here where network/internet is avaliable") {
new HTTPdemo().execute("");
}
}
The code snippet provided by me works in the following way,
1)Android device send the URL+data to server
2)Server [Azure platform used] receive the data and gives an acknowledgement
Now the Code which should be written at client side (Android) is provided to you, the later part of receiving that data at server is
- Server needs to receive the data
- An webservice should be used to do that
- Implement an webservice at server side
- The webservice will be invoked whenever android will push the URL+data
- Once you have the data ,manipulated it as you want
Post a Comment for "Unable To Insert Into Azure Via Android Application"