0

I couldn't find any help on how to call simple URL with passing one parameter, no need to return any value, just call, and my php on the server will save the passed parameter , example http://www.anysitetocall.com?parm1=newval123

Please help me with working code and what import I need as I'm new in Android and Java.

bytecode77
  • 14,163
  • 30
  • 110
  • 141
LinWeb
  • 1
  • 1
  • 1
  • Maybe tell a bit more of the environment you're programming in. –  Nov 13 '15 at 00:13
  • Why dont you learn Networking basics via some link. How about trying this http://www.vogella.com/tutorials/AndroidNetworking/article.html – AAnkit Nov 13 '15 at 00:14
  • http://programmerguru.com/android-tutorial/how-to-sync-remote-mysql-db-to-sqlite-on-android/ – Burak Karasoy Nov 13 '15 at 01:25

2 Answers2

2

A nice library to use for network requests is Volley. This is how you include it:

Add this in the dependency section of your build.gradle file to use volley

dependencies {
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
}

Its not official but a mirror copy of official Volley. It is regularly synced and updated with official Volley Repository so you can go ahead to use it without any worry.

https://github.com/mcxiaoke/android-volley

To use Volley, you must add the android.permission.INTERNET permission to your app's manifest. Without this, your app won't be able to connect to the network.

Then after you include it you can do this:

final TextView mTextView = (TextView) findViewById(R.id.text);
...

// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(this);
String url = "http://www.anysitetocall.com?parm1=newval123";

// Request a string response from the provided URL.
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener<String>() {
@Override
public void onResponse(String response) {
    // Display the first 500 characters of the response string.
    mTextView.setText("Response is: "+ response.substring(0,500));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
    mTextView.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);

For more on how to use volley visit here: http://developer.android.com/training/volley/simple.html#manifest

Answers from: Best way to incorporate Volley (or other library) into Android Studio project

and

http://developer.android.com/training/volley/simple.html#manifest

Community
  • 1
  • 1
Sloganho
  • 2,041
  • 3
  • 16
  • 20
0

I was using mostly HttpClient interface until it was depercated in API level 22.

And now I'm using openConnection() instead.

This is an example of how you can do it:

URL myURL = new URL("http://www.anysitetocall.com?parm1=newval123"); HttpURLConnection myConn = (HttpURLConnection) myURL.openConnection(); myConn.setRequestMethod("POST");

for more information https://stackoverflow.com/a/29060004/5231413

Community
  • 1
  • 1
Yariv Gavriel
  • 53
  • 1
  • 9