• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Calling a URL from Android phone

davidkebo

Lurker
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
 
Try this:

Code:
HttpClient mClient= new DefaultHttpClient();
        HttpGet get = new HttpGet("[URL]http://10.0.1.90/axis-cgi/com/ptz.cgi?[/URL]camera=1&move=home");
        try {
            mClient.execute(get);
            HttpResponse res = mClient.execute(get);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
 
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();
 
Are you accessing the browser using wifi on your network rather than the phone internet service?
 
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.
 
Code:
package urltest.android;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class urltest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button urlbutton = (Button) findViewById(R.id.urlbutton);
        
        urlbutton.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {

                runUrl();
            }

            private 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();
                    }
            
            } // End runurl()
       }); 
    }
}

Here is the code for the application, but apparently something is still wrong
 
Back
Top Bottom