0

I'm trying to send the data over to the server.

I just started learning about Volley Coding, not sure if this is the right way. Cause there is no error to the codes but when trying to send over to the server, it have no response in the logcat other than the usual "Action_down".

Please help me~

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    private static final String URL = "http://my server url";
    private TextView bssid, ssid;
    private Button btnsend, button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         RequestQueue queue = Volley.newRequestQueue(this);
        bssid = (TextView) findViewById(R.id.BSSID);
        ssid = (TextView) findViewById(R.id.SSID);
        btnsend = (Button) findViewById(R.id.btnsend);
        button = (Button) findViewById(R.id.button);

        btnsend.setOnClickListener(this);
        button.setOnClickListener(this);

    }

--Continue-- I'm able to get the result of the Button button that I wanted. --Continue--

    private void GetBSSID() {
        WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = manager.getConnectionInfo();

        TextView bssid;
        bssid = (TextView) findViewById(R.id.BSSID);
        bssid.setText(info.getBSSID());

        TextView ssid;
        ssid = (TextView) findViewById(R.id.SSID);
        ssid.setText(info.getSSID());
    }

    private void SendData() {
        WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = manager.getConnectionInfo();
        TextView bssid;
        bssid = (TextView) findViewById(R.id.BSSID);
        bssid.setText(info.getBSSID());

        StringRequest postRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.d("Response", response);
            }
        },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
//                        String response = new String();
 //                       Log.d("Error.Response", response);
                    }
                }) {
                @Override

--Continue--

I'm trying to send over a TextView instead of EditText to the server, not sure if this works.

--Continue--

 protected Map<String, String> getParams()
            {
               Map<String, String>  params = new HashMap<String, String>();

             params.put("BSSID", "http://my server url");

              return params;
              }

        };
        // Instantiate the cache
        Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); /

// Set up the network to use HttpURLConnection as the HTTP client.
        Network network = new BasicNetwork(new HurlStack());
        RequestQueue mRequestQueue;
        mRequestQueue = new RequestQueue(cache, network);

        mRequestQueue.add(postRequest);
    }

    @Override
    public void onClick(View v) {
        if (v == button) {
            GetBSSID();
        } else {
             {
                SendData();
            }
        }
    }
}
Rynn
  • 1
  • 1

0 Answers0