1

Guys i want to recieve values from MySQL into my app without using buttons. I have used wampserver for the connection. I then followed this tutorial for both, create the php file and to code in android studio: https://www.youtube.com/watch?v=38HDyEUEpCw

but, the following code has deprecated parts:

            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost("http://10.0.2.2/folder/getAllSensors.php");
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            inputStream = httpEntity.getContent();

So, i refered this link: HttpEntity is deprecated on Android now, what's the alternative?

and with it i coded this:

public class LoginActivity extends Activity {
    TextView textElement;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        StrictMode.enableDefaults();
        textElement = (TextView) findViewById(R.id.textView);
        getData();
    }
Community
  • 1
  • 1
Vishruth K
  • 11
  • 3

1 Answers1

0

In your php file, are you using GET method as well? And on your layout xml file, does your TextView have this attribute: android:text="textView"? Try to check also each jsonObject if it's able to retrieve data from php. You can also post your php code so we'll be able to check as well.

fmpsagara
  • 485
  • 5
  • 17
  • I have added the php file as u have asked me. If i use android:text="textView", it prints textView on the activity when run and without android:text="textView" gives me a blank screen – Vishruth K Feb 17 '16 at 18:54
  • Then that could possibly mean that there's no value sent to textView. By the way, do you see the error message log on your logcat? If yes, you can replace "Error" to e.getMessage(); for you to get the exact error that's causing the issue. – fmpsagara Feb 17 '16 at 19:12
  • okay i got the error on the log cat and i got the solution as well. I hadnt added user permissions in manifest file to access internet. Thank You for your time. – Vishruth K Feb 19 '16 at 07:13
  • Oh! I'm glad that you're able to fix the error! Have a good day! – fmpsagara Feb 19 '16 at 16:57