1

I am using a code that retrieves and shows the Changelog if its the first startup, simple as that :).

This works well on Android 2.3 and lower, but when trying on Custom ICS-ROM and on Emulator, it fails...

if(lastVersion < currentVersion) {

           InputStream content = null;
           try {
               HttpGet httpGet = new HttpGet("http://dreamhawk.blinkenshell.org/changelog.txt");
               httpGet.setHeader("Content-Type", "text/plain; charset=utf-8");
               HttpClient httpclient = new DefaultHttpClient();
               // Execute HTTP Get Request
               HttpResponse response = httpclient.execute(httpGet);
               content = response.getEntity().getContent();


           } catch (Exception e) {
               //handle the exception !
           }
           if(content == null) {
               lastVersion = Prefs.getInt("firstRun", -1);
               Toast.makeText(Main.this,
                         "Failed fetching changelog on first run, connected to Internet?",
                            Toast.LENGTH_SHORT).show();

           } else {
           BufferedReader r = new BufferedReader(new InputStreamReader(content));
           StringBuilder total = new StringBuilder();
           String line;
           String NL = System.getProperty("line.separator");
           try {
               while ((line = r.readLine()) != null) {
                   total.append(line + NL);
               }
           } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
           }

           String page = total.toString();

           Dialog dialog = new Dialog(Main.this);

           dialog.setContentView(R.layout.custom_dialog);
           dialog.setTitle(R.string.changelog);
           dialog.setCanceledOnTouchOutside(true);

           TextView text = (TextView) dialog.findViewById(R.id.text);
           text.setTextSize(13);
           text.setText(page);
           dialog.show();
           }
       }     

Apparently, content is null, and i don't know why.. Because it's working on other android-versions, i don't know what could possibly be wrong... But being the noob that i am, i am probably using some bad codes...

Care to help? :)

DreamHawk
  • 785
  • 2
  • 9
  • 20

2 Answers2

0

Considered if the issue could be related to this? You can't perform networking operations on main thread from honeycomb (3.0) and forward.

Community
  • 1
  • 1
Warpzit
  • 27,966
  • 19
  • 103
  • 155
0

Try checking the inputstream for data-availability instead of != null. See answer: https://stackoverflow.com/a/1524309/222474

Community
  • 1
  • 1
Tom Siwik
  • 992
  • 9
  • 22