Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


BlogReader seems to only pull data under wireless connection

Hi all,

I finished the BlogReader app but noticed it doesn't work when I'm not connected to a wireless network. Is there extra code required to connect to a cellular network also? It is most likely related to the newer SDK environment I guess since my code is identical to Ben's but I didn't see any teacher's notes on this. Any comments or suggestions would be appreciated.

3 Answers

Calvin Nix
Calvin Nix
43,828 Points

Hey Joey,

So you are saying that if you are connected to the internet via Cellular Network you are unable to connect to the blog reader app?

This is interesting... I tested my application using a Nexus 7 tablet that is WiFi only so I did not run into this issue.

Are you testing on a real device or the emulator?

Hi Calvin,

Yes, I am using my galaxy to test and it only fully works when connected to a wireless network. Interestingly enough, today I found out that the problem seems to be with loading the mainlistActivity. It will not load the items when it can only rely on a cellular network. I found this out after using wireless to load the posts, turning it off, then clicking on an item. Every time the posts would load into the blogwebviewActivity screen regardless of whether it relied on my home wireless or cellular wireless. I've included 2 parts of my code related to connecting to the internet that could be wrong. Any hints or suggestions would be much appreciated.

private boolean isNetworkAvailable() {
        ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = manager.getActiveNetworkInfo();

        boolean isAvailable = false;
        if (networkInfo != null && networkInfo.isConnected()) {
            isAvailable = true;
        return isAvailable;
        protected JSONObject doInBackground(Object... params) {
            int responseCode = -1;
            JSONObject jsonResponse = null;

            try {
                URL blogFeedUrl = new URL("http://blog.teamtreehouse.com/api/get_recent_summary/?count=" + NUMBER_OF_POSTS);
                HttpURLConnection connection = (HttpURLConnection) blogFeedUrl.openConnection();

                responseCode = connection.getResponseCode();
                if (responseCode == HttpURLConnection.HTTP_OK) {
                    InputStream inputStream = connection.getInputStream();
                    Reader reader = new InputStreamReader(inputStream);
                    int contentLength = connection.getContentLength();
                    char[] charArray = new char[contentLength];
                    String responseData = new String(charArray);
                    jsonResponse = new JSONObject(responseData);
                else {
                Log.i(TAG, "Unsuccessful HTTP Response Code: " + responseCode);
Refael Ozeri
Refael Ozeri
18,274 Points

Hi, I have the same exact problem! Any solutions regarding this??

I still don't know but hopefully Ben Jakuben responds so we don't have to tell our users our app serves no purpose unless they're at home or Starbucks.