Showing progress in notification bar
<p>I am showing the progress bar in notification area by using the code below. I am not sure it is right or not. Please check and let me know. I want to show progress bar while the video is uploading and want to dismiss after uploading. Please give me suggestions.</p>

<pre><code>protected Void doInBackground(Void... arg0) {   

            Intent intent = new Intent();
            final PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
            // configure the notification          
            notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
            notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.uploadprogress);
            notification.contentIntent = pendingIntent;
            notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.progressbar);
            notification.contentView.setTextViewText(R.id.status_text, "Uploading...");
            notification.contentView.setProgressBar(R.id.status_progress, 100, progress, false);

            notificationManager = (NotificationManager) getApplicationContext().getSystemService(
                    getApplicationContext().NOTIFICATION_SERVICE);

            notificationManager.notify(10, notification);

            final SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(getApplicationContext());
            UUID uniqueKey = UUID.randomUUID();
                fname = uniqueKey.toString();
                Log.e("UNIQUE NAME", fname);
                String hostName = "MY HOST NAME";
                String username = "test";
                String password = "****";
                String location = selectedPath;         
                InputStream in = null;
                try {
                    Thread upload = new Thread() {

                        @Override
                        public void run() {

                            for (int i = 1; i &lt; 100; i++) {   
                                progress=progress+1;
                                notification.contentView.setProgressBar(R.id.status_progress, 100, progress, false);                               
                                // inform the progress bar of updates in progress
                                notificationManager.notify(id, notification);                      
                                try {
                                    Thread.sleep(2000);
                                } catch (InterruptedException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }      
                        }
                    };
                    upload.run();
                    FTPClient ftp = new FTPClient();
                    ftp.connect(hostName);
                    ftp.login(username, password);

                    ftp.setFileType(FTP.BINARY_FILE_TYPE);
                    ftp.enterLocalPassiveMode();
                    ftp.changeWorkingDirectory("/uploads");

                    int reply = ftp.getReplyCode();
                    System.out.println("Received Reply from FTP Connection:" + reply);

                    if (FTPReply.isPositiveCompletion(reply)) {
                        System.out.println("Connected Success");
                    }

                    File f1 = new File(location);
                    in = new FileInputStream(f1);

                    ftp.storeFile(fname+"."+extension, in);

                    System.out.println("SUCCESS");
                    System.out.println("Video Title:" +strTitle+" is uploaded successfully");
                    System.out.println("Video Name:" +fname+" is uploaded successfully");
                    ftp.logout();
                    ftp.disconnect();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                StringBuffer inStreamBuf = new StringBuffer();
                strUserName = prefs.getString(
                        getResources().getString(R.string.username), null);
                strToken = prefs.getString(
                        getResources().getString(R.string.token), null);
                url = prefs.getString("VALUE", null);
                try {                   
                        inStreamBuf = XmlUtil.getUploadAuthResponse(url,
                                strUserName, strToken, strType, strTitle,
                                fname, strDesc, strCatId, strTags, strAccess,
                                strComments, strEmbed, strRating, strPublish);
                        strXmlResponse = inStreamBuf.toString();
                        Log.e("Response:", strXmlResponse);
                        DocumentBuilder db = DocumentBuilderFactory
                                .newInstance().newDocumentBuilder();
                        InputSource is = new InputSource();
                        is.setCharacterStream(new StringReader(strXmlResponse));
                        Document doc = db.parse(is);
                        NodeList nodes = doc
                                .getElementsByTagName(getResources().getString(
                                        R.string.xmlResponse));
                        Element element = (Element) nodes.item(0);
                        NodeList nl_request_type = element
                                .getElementsByTagName(getResources().getString(
                                        R.string.response));
                        Element el_request_type = (Element) nl_request_type
                                .item(0);
                        String strType = getCharacterDataFromElement(el_request_type);
                        // System.out.println("Response-----------&gt;"+strType);
                        if (strType.equalsIgnoreCase(getResources().getString(
                                R.string.success))) {   
                            finish();
                            Intent intent1 = new Intent(NewVideoActivity.this,
                                    MainscreenActivity.class);
                            startActivity(intent);
                        } else if (strType.equalsIgnoreCase(getResources()
                                .getString(R.string.expired))) {
                            XmlUtil.session = null;
                            Intent intent2 = new Intent(NewVideoActivity.this,
                                    MainscreenActivity.class);
                            startActivity(intent);
                            finish();
                            System.exit(0);
                        }                                           
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }   
                notificationManager.cancel(10); 
                return null;

            }
</code></pre>
