I am new in android i am using php web api to transfer data from app to mysql in xampp but getting json data works fine on emulator showing correct data but on real device it is not showing anything . Where is the issue??
public class MainActivity extends AppCompatActivity {
public class DownloadTask extends AsyncTask<String,Void,String>{
@Override
protected String doInBackground(String... urls) {
String result = "";
URL url;
HttpURLConnection urlConnection =null;
try {
url = new URL(urls[0]);
urlConnection= (HttpURLConnection) url.openConnection();
InputStream inputStream=urlConnection.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
int data = reader.read();
while (data!=-1)
{
char current = (char)data;
result+=current;
data=reader.read();
}
return result;
}catch(Exception e)
{
e.printStackTrace();
Log.i("Error",e.getMessage());
return null;
}
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if(s!=null)
{
try{
TextView t = (TextView)findViewById(R.id.textview);
t.setText(s);
}
catch (Exception a)
{
Log.e("Error",a.getMessage());
}
}}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DownloadTask downloadTask = new DownloadTask();
downloadTask.execute("http://192.168.0.69:8082/AndroidData/sample.php");
}
}