0

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");
    }
    }
  • 1
    check this answer https://stackoverflow.com/a/50834600/1712446 – Azhagthott Jan 31 '20 at 04:56
  • I have tried that too but it didn't work that's why I posted this question – Gunjan Bansal Jan 31 '20 at 05:06
  • is your real device connected on same network of pc? – mili2501 Jan 31 '20 at 05:18
  • Yes they both are on the same network . – Gunjan Bansal Jan 31 '20 at 05:22
  • try opening the url "http://192.168.0.69:8082/AndroidData/sample.php" in your device and check if it works, can please show your logcat – Azhagthott Jan 31 '20 at 05:46
  • Mylogcat is 2020-01-31 12:24:54.037 6493-6493/com.example.workwithjson I/zygote: Not late-enabling -Xcheck:jni (already on) 2020-01-31 12:24:54.098 6493-6493/com.example.workwithjson W/zygote: Unexpected CPU variant for X86 using defaults: x86 2020-01-31 12:24:54.340 6493-6527/com.example.workwithjson D/OpenGLRenderer: HWUI GL Pipeline 2020-01-31 12:24:54.356 6493-6524/com.example.workwithjson D/NetworkSecurityConfig: No Network Security Config specified, using platform default 2020-01-31 12:24:54.393 6493-6527/com.example.workwithjson I/zygote: android::hardware::configstore::V1_0::ISurfa – Gunjan Bansal Jan 31 '20 at 06:56

0 Answers0