Find below detail for API : 

*URL :* http://192.168.0.19/monika/slim_prj/public/code

*Request Parameter *(in POST)

- mac_address

- key

*Response* (in JSON) - 

{
"status": 1,
"message": "qYNoQBImXRhOMety"
}


my code goes here--> 

package com.medmainfomatix.myapplication1;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


public class MainActivity extends AppCompatActivity {

 EditText emailText;
 EditText emailText1;
 TextView responseView;
 ProgressBar progressBar;

 static final String API_URL = 
"http://192.168.0.19/monika/slim_prj/public/code/";;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 responseView = (TextView) findViewById(R.id.responseView);
 emailText = (EditText) findViewById(R.id.emailText);
 emailText1= (EditText) findViewById(R.id.emailText1);

 progressBar = (ProgressBar) findViewById(R.id.progressBar);

 Button queryButton = (Button) findViewById(R.id.queryButton);
 queryButton.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View v) {
 new RetrieveFeedTask().execute();
 }
 });
 }

 class RetrieveFeedTask extends AsyncTask<Void, Void, String> {

 private Exception exception;
 String mac_address = emailText.getText().toString();
 String key= emailText1.getText().toString();

 protected void onPreExecute() {
 progressBar.setVisibility(View.VISIBLE);
 responseView.setText("");
 }

 protected String doInBackground(Void... urls) {

 // Do some validation here

 try {
 URL url = new URL(API_URL + "mac_address=" + mac_address + "Key=" + key);
 HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
 try {
 BufferedReader bufferedReader = new BufferedReader(new 
InputStreamReader(urlConnection.getInputStream()));
 StringBuilder stringBuilder = new StringBuilder();
 String line;
 while ((line = bufferedReader.readLine()) != null) {
 stringBuilder.append(line).append("\n");
 }
 bufferedReader.close();
 return stringBuilder.toString();
 }
 finally{
 urlConnection.disconnect();
 }
 }
 catch(Exception e) {
 Log.e("ERROR", e.getMessage(), e);
 return null;
 }
 }

 protected void onPostExecute(String response) {
 if(response == null) {
 response = "THERE WAS AN ERROR";
 }
 progressBar.setVisibility(View.GONE);
 Log.i("INFO", response);
 responseView.setText(response);
 // TODO: check this.exception
 // TODO: do something with the feed

// try {
// JSONObject object = (JSONObject) new JSONTokener(response).nextValue();
// String requestID = object.getString("requestId");
// int likelihood = object.getInt("likelihood");
// JSONArray photos = object.getJSONArray("photos");
// .
// .
// .
// .
// } catch (JSONException e) {
// e.printStackTrace();
// }
 }
 }
}


-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/90c19ce6-4349-4ac8-908e-7ee72878e668%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to