Calling a URL from Android phone


Last Updated:

  1. davidkebo

    davidkebo Member

    Hello,
    I am calling a URL from the Android phone
    This URL is supposed to move a camera connected on the same network
    Here is the code for the URL:
    url = new URL("http://10.0.1.90/axis-cgi/com/ptz.cgi? camera=1&move=home");
    URLConnection cameraConnection = url.openConnection();
    cameraConnection.connect();


    I get no response when I run this code from the phone. Is this the
    right way to call a URL from an Android phone ? Any suggestions ?
    Thanks in advance

    Advertisement
  2. metter

    metter Active Member

    Try this:

    Code (Text):
    1. HttpClient mClient= new DefaultHttpClient();
    2.         HttpGet get = new HttpGet("[URL]http://10.0.1.90/axis-cgi/com/ptz.cgi?[/URL]camera=1&move=home");
    3.         try {
    4.             mClient.execute(get);
    5.             HttpResponse res = mClient.execute(get);
    6.         } catch (Exception e) {
    7.             // TODO Auto-generated catch block
    8.             e.printStackTrace();
    9.         }
  3. davidkebo

    davidkebo Member

    The url runs fine in the phone's browser, I tried your suggestion but still no response. Here is the function I use.

    public void runUrl()
    {

    HttpClient mClient= new DefaultHttpClient();
    HttpGet get = new HttpGet("http://10.0.1.90:80/axis-cgi/com/ptz.cgi?camera=1&move=home");
    try
    {
    mClient.execute(get);
    HttpResponse res = mClient.execute(get);
    }
    catch (Exception e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    I call the function from the main program:

    runUrl();
  4. Barbara

    Barbara Well-Known Member

    Are you accessing the browser using wifi on your network rather than the phone internet service?
  5. davidkebo

    davidkebo Member

    Thanks for replying.

    Im using wifi on my local network. The phone is connected to the wifi network. I made sure the URL is valid by calling it for the phone browser first, and it worked fine. Now in just try to call the same URL from my application, still no success.
  6. davidkebo

    davidkebo Member

    Code (Text):
    1.  
    2. package urltest.android;
    3.  
    4. import org.apache.http.HttpResponse;
    5. import org.apache.http.client.HttpClient;
    6. import org.apache.http.client.methods.HttpGet;
    7. import org.apache.http.impl.client.DefaultHttpClient;
    8.  
    9. import android.app.Activity;
    10. import android.os.Bundle;
    11. import android.view.View;
    12. import android.widget.Button;
    13.  
    14. public class urltest extends Activity {
    15.     /** Called when the activity is first created. */
    16.     @Override
    17.     public void onCreate(Bundle savedInstanceState) {
    18.         super.onCreate(savedInstanceState);
    19.         setContentView(R.layout.main);
    20.        
    21.         Button urlbutton = (Button) findViewById(R.id.urlbutton);
    22.        
    23.         urlbutton.setOnClickListener(new Button.OnClickListener() {
    24.             public void onClick(View v) {
    25.  
    26.                 runUrl();
    27.             }
    28.  
    29.             private void runUrl() {
    30.                
    31.                      HttpClient mClient= new DefaultHttpClient();
    32.                     HttpGet get = new HttpGet("http://10.0.1.90:80/axis-cgi/com/ptz.cgi?camera=1&move=home");
    33.                     try
    34.                     {
    35.                         mClient.execute(get);
    36.                         HttpResponse res = mClient.execute(get);
    37.                     }
    38.                     catch (Exception e)
    39.                     {
    40.                         // TODO Auto-generated catch block
    41.                         e.printStackTrace();
    42.                     }
    43.            
    44.             } // End runurl()
    45.        });
    46.     }
    47. }
    48.  
    Here is the code for the application, but apparently something is still wrong

Share This Page