Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old November 2nd, 2009, 11:44 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Nov 2009
Posts: 7
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 2 Times in 1 Post
Default Calling a URL from Android phone

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

Advertisements
davidkebo is offline  
Last edited by davidkebo; November 2nd, 2009 at 11:48 PM.
Reply With Quote
sponsored links
Old November 3rd, 2009, 01:46 AM   #2 (permalink)
Junior Member
 
Join Date: Oct 2009
Posts: 33
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this:

Code:
HttpClient mClient= new DefaultHttpClient();
        HttpGet get = new HttpGet("http://10.0.1.90/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();
        }
metter is offline  
Last edited by metter; November 3rd, 2009 at 01:47 AM.
Reply With Quote
Old November 3rd, 2009, 09:14 AM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Nov 2009
Posts: 7
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 2 Times in 1 Post
Default Thanks for replying

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();
davidkebo is offline  
Last edited by davidkebo; November 3rd, 2009 at 04:28 PM.
Reply With Quote
Old November 3rd, 2009, 09:18 AM   #4 (permalink)
Senior Member
 
Barbara's Avatar
 
Join Date: Oct 2009
Posts: 840
 
Device(s): Droid 3 Asus TF101
Carrier: Not Provided

Thanks: 9
Thanked 43 Times in 26 Posts
Default

Are you accessing the browser using wifi on your network rather than the phone internet service?
Barbara is offline  
Reply With Quote
Old November 3rd, 2009, 04:27 PM   #5 (permalink)
New Member
Thread Author (OP)
 
Join Date: Nov 2009
Posts: 7
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 2 Times in 1 Post
Default Using local WiFi network

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.
davidkebo is offline  
Reply With Quote
Old November 3rd, 2009, 04:32 PM   #6 (permalink)
New Member
Thread Author (OP)
 
Join Date: Nov 2009
Posts: 7
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 2 Times in 1 Post
Default The Application Code

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
davidkebo is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:09 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.