Hi, I recently created a new feature in my apps that allows the user
to check if there is an update by getting an HTML page, looking
through it, and comparing the versions. However, this is causing the
application to force close on startup for many of my users using
Samsung and HTC phones, but works just as intended on droid x,
incredible, and 2. I can't get my hands on any of the phones that are
currently crashing and have no idea where to start in fixing it. I use
a AsyncTask to search, and start it using

new CheckForUpdate().execute();

the CheckForUpdate class is defined as followed:

         private class CheckForUpdate extends AsyncTask<String, Integer,
String> implements OnCancelListener
         {
                 ProgressDialog loadingDialog;
                 AlertDialog noInternetDialog;
                 AlertDialog updateAvailiableDialog;
                 AlertDialog updateUnavailiableDialog;

                        @Override
                        protected void onPreExecute()
                        {
                                loadingDialog = new
ProgressDialog(GetHimToTheGreekSoundboard.this);
        
loadingDialog.setMessage(getString(R.string.checking_for_update));
                        loadingDialog.setCancelable(true);
                        loadingDialog.setOnCancelListener(this);
                        loadingDialog.setIndeterminate(true);

                        updateAvailiableDialog = new
AlertDialog.Builder(GetHimToTheGreekSoundboard.this)
                        .setIcon(R.drawable.icon)
                     .setTitle(R.string.update)
                     .setPositiveButton(R.string.update, new
DialogInterface.OnClickListener() {
                                                        public void 
onClick(DialogInterface dialog, int which) {
                                                                Intent intent = 
new Intent(Intent.ACTION_VIEW);
                                                        
intent.setData(Uri.parse("market://details?
id=com.brandao.GetHimToTheGreekSoundboard"));
                                                        startActivity(intent);
                                                        }
                                                })
                                        .setNegativeButton(R.string.close, new
DialogInterface.OnClickListener() {
                                                        public void 
onClick(DialogInterface dialog, int which) {
                                                                //do nothing
                                                        }
                                                }).create();

                        noInternetDialog = new
AlertDialog.Builder(GetHimToTheGreekSoundboard.this)
                       .setIcon(R.drawable.icon)
                        .setTitle(R.string.no_internet)
                        .setMessage(R.string.unable_to_connect)
                        .setPositiveButton("Continue", new
DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int
whichButton) {

                            }
                        })
                        .create();

                        updateUnavailiableDialog = new
AlertDialog.Builder(GetHimToTheGreekSoundboard.this)
                    .setIcon(R.drawable.icon)
                     
.setTitle(R.string.update).setMessage(R.string.no_update_availiable)
                     .setNegativeButton(R.string.close, new
DialogInterface.OnClickListener() {
                                                        public void 
onClick(DialogInterface dialog, int which) {
                                                                //do nothing
                                                        }
                                                })
                     .create();


                                loadingDialog.show();
                        }

                        @Override
                        protected void onCancelled()
                        {
                                Toast.makeText(GetHimToTheGreekSoundboard.this, 
"Checking for
update cancelled", Toast.LENGTH_SHORT).show();
                        }

                        @Override
                        protected void onPostExecute(String result)
                        {
                                loadingDialog.dismiss();

                        if (result == null)
                        {
                                noInternetDialog.show();
                                return;
                        }
                        else if (result != "no_update")
                        {
                                updateAvailiableDialog.setMessage(result);
                                updateAvailiableDialog.show();
                        }
                        else
                                updateUnavailiableDialog.show();
                        }

                        @Override
                        protected String doInBackground(String... params)
                        {
                                String url = 
generateHTMLPage("http://www.androidpit.com/en/
android/market/apps/app/com.brandao.gethimtothegreeksoundboard/Get-Him-
ToThe-Greek-Soundboard");

                                if (url == null)
                                        return null;

                                String preTag = "Version ";
                                String onlineVersion = "";
                                String updateNotes = 
getString(R.string.no_update_description);

                                for (int i = 0; i < url.length() - 
preTag.length() - 20; i++)
                                {
                                        if (url.substring(i, i + 
preTag.length()).equals(preTag))
                                        {
                                                onlineVersion = url.substring(i 
+ preTag.length(), i +
preTag.length() + 5);
                                                break;
                                        }
                                }

                                if 
((onlineVersion.equals(getString(R.string.version_name))))
                                        return "no_update";
                                else
                                {
                                        String tag = "Recent changes: ";
                                        for (int i = 0; i < url.length() - 
tag.length() - 20; i++)
                                        {
                                                if (url.substring(i, i + 
tag.length()).equals(tag))
                                                {
                                                        updateNotes = 
url.substring(i + tag.length(), i + tag.length()
+ url.substring(i + tag.length()).indexOf("\" />  <meta name=\"keywords
\" content=\"Get Him ToThe Greek Soundboard,"));
                                                        break;
                                                }
                                        }

                                        return 
getString(R.string.update_availiable) + "\n" + "\n" +
getString(R.string.version) + ": " + onlineVersion + "\n" +  " - " +
updateNotes;
                                }
                        }

                        public String generateHTMLPage(String url)
                        {
                                        HttpClient client = new 
DefaultHttpClient();
                                         HttpGet request = new HttpGet(url);
                                         HttpResponse response = null;
                                        try {
                                                response = 
client.execute(request);
                                        } catch (ClientProtocolException e) {
                                                e.printStackTrace();
                                                return null;
                                        } catch (IOException e) {
                                                e.printStackTrace();
                                                return null;
                                        }

                                         String html = "";
                                         InputStream in = null;
                                        try {
                                                in = 
response.getEntity().getContent();
                                        } catch (IllegalStateException e) {
                                                e.printStackTrace();
                                                return null;
                                        } catch (IOException e) {
                                                e.printStackTrace();
                                                return null;
                                        }
                                         BufferedReader reader = new 
BufferedReader(new
InputStreamReader(in));
                                         StringBuilder str = new 
StringBuilder();
                                         String line = null;
                                         try {
                                                while((line = 
reader.readLine()) != null)
                                                 {
                                                     str.append(line);
                                                 }
                                        } catch (IOException e) {
                                                e.printStackTrace();
                                                return null;
                                        }
                                         try {
                                                in.close();
                                        } catch (IOException e) {
                                                e.printStackTrace();
                                                return null;
                                        }
                                         html = str.toString();

                                         return html;
                        }

                        @Override
                        public void onCancel(DialogInterface dialog) {
                                this.cancel(true);
                        }
         }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to