Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:55:26+00:00 2026-05-27T22:55:26+00:00

I want my android app to get data from an online database. Here are

  • 0

I want my android app to get data from an online database. Here are the two scenarios:

  • When I create my db with xampp and I am using the httpost function with my local machines’ ip as argument I see as output what I expect to see (the database at logcat).

My question is: if I run the application from my phone, will it connect to my local machine server or not?

  • I also have a site (lets say mysite.com) and in order not to buy another server I am placing the php file and the database on that server. But then my android app connects (or so I think) to the server, but it prints out at logcat the whole html site. I am thinking that this is because the server requires a username and a password and I do not know if I provided them or not?

So, what do you suggest to do? I want my database being sent to my app (so as to use it later).

My code is shown below (I have in comments the only that changes between 2 scenarios)

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    setImageClickListener();

}

private void setImageClickListener() {
    ImageView map_image=(ImageView)findViewById(R.id.map_icon);
    map_image.setOnTouchListener(new ImageView.OnTouchListener() {
    //OnTouchListener listener = new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if(!(event.getAction() == MotionEvent.ACTION_DOWN))
                return false; //If the touch event was not putting the finger down on the screen, return false(Actions may be move, up, and so on)
            final float x = event.getX();
            final float y = event.getY();
            //System.out.println("Coordinates of button pressed are: X is %d"+x+" and Y is %d"+ y);
            if(x>335 && x<395 && y>225 && y< 235)
                DoFirst();

           return true;
        }

});

}
@SuppressWarnings("null")
private void DoFirst() {
    Log.d("SnowReportApp","Do first thing");
    setContentView(R.layout.layout_1);
    String result = "";
    InputStream is = null;
    StringBuilder sb=null;
    //the year data to send
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();//() before
    nameValuePairs.add(new BasicNameValuePair("year","1980"));
    //http post
    try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("192.168.1.67/test.php"); // only this changes to my server url : mysite.com/httpdocs/test.php
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
    }catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());
    }
    //convert response to string
    try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
            }
            is.close();

            result=sb.toString();
    }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
    }

    //parse JSON data
    try{
            //JSONObject json_data_1 = new JSONObject(result); 
            JSONArray jArray = new JSONArray(result);
            for(int i=0;i<jArray.length();i++){
                   JSONObject json_data = jArray.getJSONObject(i);
                    Log.i("log_tag","id: "+json_data.getInt("id")+
                            ", name: "+json_data.getString("name")+
                            ", sex: "+json_data.getInt("sex")+
                            ", birthyear: "+json_data.getInt("birthyear")
                    );
            }

    }catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
    }

} 

My php file located on either c:\xampp\htdocs or on mysite server is this:

<?php

  mysql_connect("127.0.0.1","root","");

  mysql_select_db("peopledata");

  $q=mysql_query("SELECT * FROM people WHERE birthyear>'".$_REQUEST['year']."'");

  while($e=mysql_fetch_assoc($q))

          $output[]=$e;

       print(json_encode($output));

mysql_close();?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:55:26+00:00Added an answer on May 27, 2026 at 10:55 pm

    My question is: if I run the application from my phone, will it
    connect to my local machine server or not?

    The answer is probably not. It really all depends on:

    • Whether you’re using Wifi or Carrier data (3G, etc)
    • Whether your DB ports are open (PC firewall)
    • If Carrier data, is your PC reachable from the Internet (static IP)

    You’re better off using mysite.com for your DB and whatever backend you need.

    As for your other questions, I cannot answer them as they’re quite vague. Consider researching your problem some more and perhaps come back with a targeted set of questions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an android app. I want to pass some data across the
I have a android app that is quite simple it fetches data from the
I am developing an app for android where I need some data from a
I've researched and followed how to get my android app to backup the data
I want to send a csv file from Android to Python AppEngine. I'm using
I am using OpenGL ES to perform drawing in an Android app. I want
I want my Android app to take a picture, as part of something larger
I want to implement an android app which compares recorded audio files with our
I want to update a Application on Android App Market but the problem is
I'm building an Android app and I want to copy the text value of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.