This example describes the use of Android programming custom notification. Share to everyone for your reference, specific as follows:
Notification is the best way for your application to alert users without using an activity, notification is an invisible program component that alerts users to events that require attention.
As part of the UI, notification is the best fit for mobile devices. Users may have their phones with them at all times. In general, users will open several programs in the background, but they will not notice them. In such a case, it is important to be able to notify the user when there are events that need attention.
Notification is managed by Notificationmanger, and currently includes the following capabilities:
Create a status bar icon.
Displays additional information (and starts a intent) in the Extended Status bar window.
Flashing lights or LEDs.
Telephone vibration.
Audible warning sounds (ringtones, saved sound files).
Custom Notification Effect Chart:
Custom layout file:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/" Apk/res/android "
android:orientation=" vertical "
android:layout_width=" match_parent "
android:layout" _height= "Match_parent" >
<textview
android:id= "@+id/tv_rv" android:layout_width= "Wrap_content"
"
android:layout_height=" wrap_content "
android:text=" haha "
/>
<progressbar
Style = "@android: style/widget.progressbar.horizontal"
android:id= "@+id/pb_rv"
android:layout_width= "Wrap_ Content "
android:layout_height=" wrap_content "
/>
</LinearLayout>
Create notification:
public class Customnotificationactivity extends activity {Notificationmanager Notificationmanager;
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main); Gets the Notificationmanager Notificationmanager = (Notificationmanager) Getsystemservice of the system (Context.notification_
SERVICE);
public void Click (View view) {//Instantiate a notification String tickertext = "IP number set complete";
Long when = System.currenttimemillis ();
Notification Notification = new Notification (R.drawable.icon, Tickertext, when);
Can not manually clean//notification.flags= notification.flag_no_clear;
Add music//notification.sound = Uri.parse ("/sdcard/haha.mp3");
Set user clicks Notification Action//Pendingintent deferred intent Intent Intent = new Intent (this,bactivity.class);
Pendingintent pendingintent = pendingintent.getactivity (this, 0, intent, 0);
Notification.contentintent = pendingintent;
Custom interface Remoteviews RV = new Remoteviews (Getpackagename (), r.layout.noti_layout);
Rv.settextviewtext (R.ID.TV_RV, "I am a custom notification");
Rv.setprogressbar (R.ID.PB_RV, n, false);
Notification.contentview = RV;
Pass the defined notification to Notificationmanager notificationmanager.notify (0, notification);
}
}
I hope this article will help you with your Android programming.