php - Need to acces localhost from my android device -


i have php file in following folder:

c:\wamp\www\android_test\fetch_data2 

i need able access file application unable access of now. here java code , highlight need fix. can access php file computer through localhost/android_data......, cannot access phone browser. have no code written in accompanying xml file , maybe why php file not show on application.

addition notes: want app display php file connected mysql data base , outputs:

 [{"name":"user1","received_power":"-75.12207037710479","tower":"4","status":"0"},{"name":"user2","received_power":"18.89454151068304","tower":"3","status":"0"}] 

my java file called mysqldata.java has following inside:

package com.example.qosmetre2; import java.io.bufferedreader; import java.io.inputstream; import java.io.inputstreamreader; import java.util.arraylist;  import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.httpclient; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.defaulthttpclient; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject;  import android.app.activity; import android.net.parseexception; import android.os.bundle; import android.util.log; import android.widget.toast; import java.util.arraylist;  import java.util.hashmap;  import java.util.list;   import org.apache.http.namevaluepair;  import org.json.jsonarray;  import org.json.jsonexception;  import org.json.jsonobject;   import android.app.listactivity;  import android.app.progressdialog;  import android.content.intent;  import android.os.asynctask;  import android.os.bundle;  import android.util.log;  import android.view.view;  import android.widget.adapterview;  import android.widget.adapterview.onitemclicklistener;  import android.widget.listadapter;  import android.widget.listview;  import android.widget.simpleadapter;  import android.widget.textview;  public class mysqldata extends listactivity {      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         string result = null;         inputstream = null;         stringbuilder sb=null;         //string result=null;         arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();         //http post          try{             httpclient httpclient = new defaulthttpclient();             httppost httppost = new httppost("http://174.112.97.111/android_test/fetch_data2.php");             httppost.setentity(new urlencodedformentity(namevaluepairs));             httpresponse response = httpclient.execute(httppost);             httpentity entity = response.getentity();             = entity.getcontent();         }catch(exception e){             log.e("log_tag", "error in http connection"+e.tostring());         }          //convert response string          try{             bufferedreader reader = new bufferedreader(new inputstreamreader(is,"iso-8859-1"),8);             sb = new stringbuilder();             sb.append(reader.readline() + "\n");             string line="0";             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());         }         //paring data          string nam;         int rec_pow;         int tow;         int stat;          try{         jsonarray jarray = new jsonarray(result);         jsonobject json_data=null;          for(int i=0;i<jarray.length();i++){                 json_data = jarray.getjsonobject(i);                 nam=json_data.getstring("name");                 rec_pow=json_data.getint("recieved_power");                 tow=json_data.getint("tower");                 stat=json_data.getint("status");          }          }catch(jsonexception e1){             toast.maketext(getbasecontext(), "could not parse data", toast.length_long).show();         }catch (parseexception e1){             e1.printstacktrace();          }      }  } 

there file called mainactivity.java has nothing inside except default stuff, , there xml file called main_activity.xml has nothing inside it.

here andoidmanifest.xml:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.qosmetre2" android:versioncode="1" android:versionname="1.0" >  <uses-sdk     android:minsdkversion="11"     android:targetsdkversion="17" />  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name="com.example.qosmetre2.mainactivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>      <activity         android:name=".mysqldata"         android:label="all data" >      </activity>   </application> 

if both devices on same network, , you'll using app when @ home/connected same network, can use local ip address assigned computer router, 192.168.1.4

if you're going want use app on 3g/4g or wifi connection away computer, you'll need edit routers port forwarding settings , you'll connect using router's ip address. can register free domain name connected ip address won't have remember bunch of numbers.

this not coding issue though...


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -