• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Webdata shows in browser, not in app

GWE

Lurker
Hi,
Newbie Android.
Testing an app retrieving data from website fails. Calling the same website with a laptopbrowser, it shows the data.

Result of testing the app = src/empty.php !!!
How come? Help is appreciated.

Here the main activity:

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ReadWebpageAsyncTask extends Activity {
private TextView textView;

@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read_webpage_async_task);
textView = (TextView) findViewById(R.id.TextView01);
}

private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
@override
protected String doInBackground(String... urls) {
String response = "";
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse execute = client.execute(httpGet);
InputStream content = execute.getEntity().getContent();

BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}

} catch (Exception e) {
e.printStackTrace();
}
}
return response;
}

@override
protected void onPostExecute(String result) {
textView.setText(result);
}
}

public void onClick(View view) {
DownloadWebPageTask task = new DownloadWebPageTask();
task.execute(new String[] { "http://www.xxxxxxxx.xx" });

}
}
 
How does onClick() get called? I don't think Activity has that method. Try calling the DownloadWebPageTask code in there from onCreate() or onResume() instead. You will also need some permissions in your manifest file before you are allowed to access the internet.
 
Thx GeorgeN for your reply.
onClick() got called from button on layoutfile.
How can I call the DownloadWebPageTask from onCreate() ?

DownloadWebPageTask().execute("", null, ""); in onCreate() doesnot work.

Thank you
 
Something like this:

Code:
@override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_read_webpage_async_task);
    textView = (TextView) findViewById(R.id.TextView01);

    DownloadWebPageTask task = new DownloadWebPageTask();
    task.execute(new String[] { "http://www.xxxxxxxx.xx" });
}

Also, is there an exception in your logcat output? Maybe return some error string in your catch statement so you can at least see when something goes wrong.. If you are on KitKat or above you can do this:

Code:
} catch (Exception e) {
    e.printStackTrace();
    return Log.getStackTraceString(exception);
}
 
Again thanks for reply GeorgeN.
Did your trick (task.execute etcetera...) and got the webpage (src/empty.php) back (and not index.php).

This is de logcat:

10-02 21:53:10.686 780-780/? D/dalvikvm﹕ Late-enabling CheckJNI
10-02 21:53:11.287 780-780/nl.eielts.asynctask D/libEGL﹕ loaded /system/lib/egl/libEGL_MRVL.so
10-02 21:53:11.297 780-780/nl.eielts.asynctask D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_MRVL.so
10-02 21:53:11.357 780-780/nl.eielts.asynctask D/libEGL﹕ loaded /system/lib/egl/libGLESv2_MRVL.so
10-02 21:53:11.407 780-780/nl.eielts.asynctask D/GC﹕ <tid=780> OES20 ===> GC Version : GC Ver rls_pxa988_KK44_GC13.20
10-02 21:53:11.497 780-780/nl.eielts.asynctask D/OpenGLRenderer﹕ Enabling debug mode 0

Is there an explanation ?
Thank you
 
Sorry, there isn't anything useful in that logcat output, I guess you aren't hitting the exception.

I don't really understand how it can be executing src/empty.php rather than index.php?
 
Maybe not an Android issue. I carry on. Thanks anyway for your input and patience :D
regards, GWE
 
Anybody else a clue ? It is an app issue, because, when I use the Internetbrowser(chrome) on the mobile phone and use the same url as in the app, I become the index.php in stead of the empty.php

What can be wrong ????
 
Last edited:
Back
Top Bottom