android


Connecting Android Phone to local host


In my application i am using API's which are hosted on local server, and can be accessed on network. On emulator it works fine as it is connected to proper network. When I am using app on my phone it wont.
Is it possible to access local API's through phone with our normal internet connection?
I am using below http code for accessing API's.
public String getResponse(String url, int method, String postParameter) {
HttpResponse response = null;
// Creating HTTP client
HttpClient httpClient = new DefaultHttpClient();
// Creating HTTP Post
HttpPost httpPost = new HttpPost(url);
// Building post parameters
// key and value pair
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("jObj", postParameter));
// Url Encoding the POST parameters
try {
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
// Making HTTP Request
try {
response = httpClient.execute(httpPost);
// writing response to log
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
e.printStackTrace();
} catch (IOException e) {
// writing exception to log
e.printStackTrace();
} catch (Exception e2) {
e2.printStackTrace();
}
return response.toString();
}
Is there any setting which we can do for accessing through our normal internet?
Thanks in Advance
If you have it hosted on your local machine, you will have to find a way to connect both your phone and your local machine on the same network (most commonly Wifi). A simple work-around to this is creating a hotspot in your android device and connecting your local machine to it. Make sure to set the correct IP address in the android app.
Find your local machine ip address where the api's are hosted
using ipconfig and pass on the ip address in url
your url should be like 192.168.0.102 which is assigned by modem.
Answering as I cant comment, Please check that your phone is connected to your network and not using mobile data or some other WIFI network outside of your network.

Related Links

Not being able to take proper screenshots
Trying to edit JSON response to return authentication token when using devise on rails app
Global intents that are fired for all Android notifications
Query Contacts By Multiple LOOKUP_KEY
dynamically adding listview
Android integration AdWhirl and AdMob
Android table creation Failure (near “autoincrement”: syntax error)?
How to obtain the exact dpi value of android device?
Gstreamer video to opengl texture
How can I change the circle picture of a radio button in both cases checked and unchecked?
Issue with ViewPager in application
to add a last row in listview
I want to display buttons at the bottom of the screen and the buttons are inside linearLayout4,can someone pls tell me in this, am frustated now
App crashes after implementing onClickListener
Changing Android Numpad's “Next” to “Go” on submit
Android `settings.db` reference?

Categories

HOME
grok
facebook-oauth
developer-tools
nunit
numbers
serialization
components
composite-primary-key
apiblueprint
solaris
owl-carousel
bitbucket-api
spring-data-mongodb
cq5
emscripten
hpc
spring-session
android-json
google-cloud-datalab
modal-dialog
recordrtc
teechart
octave
resultset
chargify
git-extensions
angular-routing
parcelable
imageresizer
beta
tpm
uitapgesturerecognizer
google-earth
jwplayer6
slacktextviewcontroller
searchkit
google-knowledge-graph
lint
signals-slots
spring-integration-sftp
remedy
ngmaterial
google-photos
mapxtreme
custom-lists
myspace
windows-azure-queues
gogs
jclouds
udpclient
project-organization
fink
grass
invoke-sqlcmd
jaunt-api
rasterize
state-restoration
fiware-monitoring
page.js
cgi-bin
canalyzer
eoferror
liquid-layout
cwrsync
gamekit
infosphere-spl
ejb-2.x
at-job
with-statement
xml-dsig
alternate
paste
android-framework
terminate
multiautocompletetextview
android-usb
isqlquery
jeromq
dtmf
pclzip
actiondispatch
server-administration
predicatebuilder
webdev.webserver
quotation-marks
easyb
nstokenfield
qtabbar
murmurhash
lxr
web-application-project
interop-domino

Resources

Encrypt Message