android-system notification Bar message with progress bar

Source: Internet
Author: User

There's only one button on the main interface that doesn't go to the file.

The notification bar displays the layout file used Content_view.xml

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:background= "#00000000"android:orientation= "Vertical"android:padding= "5DP" > <ImageView Android:id= "@+id/content_view_image"Android:layout_width= "25DP"Android:layout_height= "25DP"android:src= "@drawable/logo"/> <TextView Android:id= "@+id/content_view_text1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "0%"Android:textcolor= "#000000"Android:layout_torightof= "@id/content_view_image"Android:layout_centerhorizontal= "true"Android:layout_margintop= "5DP"Android:layout_marginleft= "15DP"/> <ProgressBar Android:id= "@+id/content_view_progress"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"style= "@android: Style/widget.progressbar.horizontal"Android:max= "100"Android:layout_below= "@id/content_view_image"Android:layout_margintop= "4DP"/> </RelativeLayout>

Main Run class:

 PackageYyy.testandroid4;ImportJava.util.Timer;ImportJava.util.TimerTask;Importandroid.app.Activity;ImportAndroid.app.AlertDialog.Builder;Importandroid.app.Notification;ImportAndroid.app.NotificationManager;Importandroid.app.PendingIntent;ImportAndroid.content.DialogInterface;Importandroid.content.Intent;Importandroid.content.pm.PackageManager.NameNotFoundException;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.os.Message;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;Importandroid.widget.RemoteViews;ImportAndroid.widget.Toast; Public classTestandroid4activityextendsActivity {PrivateHandler Handler =NewHandler () {@Override Public voidhandlemessage (Message msg) {//TODO auto-generated Method Stub            Super. Handlemessage (msg); Switch(msg.what) { Case0: Notif.contentView.setTextViewText (r.id.content_view_text1, Len+"%"); Notif.contentView.setProgressBar (r.id.content_view_progress,Len,false); Manager.notify (0, Notif);  Break;  Case1: Toast.maketext (testandroid4activity. This, "Download Done", 0). Show ();  Break; default:                 Break;        }        }            }; PrivateButton Update,cancel; Private intlocalversion,serverversion; Private intLen; PrivateNotificationmanager Manager; PrivateNotification Notif; /**Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.main); Update=(Button) Findviewbyid (r.id.update); Update.setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View arg0) {//TODO auto-generated Method Stub//activity opened after clicking on the notification barIntent Intent =NewIntent (testandroid4activity. This, Otheractivity.class); Pendingintent pintent= Pendingintent.getactivity (testandroid4activity. This, 0, intent, 0); Manager=(Notificationmanager) Getsystemservice (Notification_service); Notif=NewNotification (); Notif.icon=R.drawable.logo; Notif.tickertext= "New Notification"; //the notification bar displays the layout file usedNotif.contentview =Newremoteviews (Getpackagename (), R.layout.content_view); Notif.contentintent=pintent; Manager.notify (0, Notif); NewDownloadthread (). Start ();                           }        }); }  }        Private classDownloadthreadextendsthread{PrivateTimer timer =NewTimer (); @Override Public voidrun () {//TODO auto-generated Method Stub            Super. Run (); Timer.schedule (NewTimerTask () {@Override Public voidrun () {//TODO auto-generated Method StubMessage msg=NewMessage (); Msg.what= 0; Msg.obj=Len;                                        Handler.sendmessage (msg); if(len = = 100) {timer.cancel (); Handler.sendemptymessage (1); }                                }            }, 0, 1000); Len= 0; Try {                 while(Len < 100) {len++; Thread.Sleep (1000); }            } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }        }            }        }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.