wad wad - 1 year ago 141
HTTP Question

Android Webservices with php

i want create web service with php code , PHP file containing the text and I want to show this text android textVeiw

I connection with URL via openConnection() but i have error in class InputStreamReader

public class MainActivity extends AppCompatActivity {
TextView text;

protected void onCreate(Bundle savedInstanceState) {

text = (TextView) findViewById(R.id.textView4);

public void onClick(View view) throws Exception {

URL hellofileurl = null;
try {
hellofileurl = new URL("http://waaddev.ahosti.net/web.php");
HttpURLConnection myfirstconnection = (HttpURLConnection) hellofileurl.openConnection();
InputStream stream = new InputStream(myfirstconnection.getInputStream());//i have error in this line
BufferedReader b = new BufferedReader(stream);
String hello = b.readLine();

} catch (Exception e) {

Answer Source

InputStream class has been deprecated.

You can use:

    URL url = new URL("http://waaddev.ahosti.net/web.php");
    URLConnection urlConnection = url.openConnection();
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

    String line;
    while ((line = bufferedReader.readLine()) != null)
         content.append(line + "\n");
    String hello = content.toString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download