So far, presumably everyone is already familiar with the use of toast to display information to users. Although it is convenient to use toast, the notifications displayed by toast are not stored permanently. It only appears for a short time on the screen and then disappears. If it contains some particularly important information, if the user does not observe the screen, then the user can easily miss it.
For those important information, a more persistent approach should be adopted. In this case, you should use the Notificationmnanger (Message manager) to display a long message that is displayed on the StatusBar (status bar) and can be easily seen by the user.
Next shows how to send a notification notification.
1. Create a project: notifications.
2. Create a new class named Notificationview in the package, and create a new name for the Notification.xml file under the Res/layout folder, which will act as a Notificationview view.
3. Documents in the Notification.xml.
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:layout_width=" fill_parent "
android:layout_height=" fill_parent "
android:o" rientation= "vertical" >
<textview
android:layout_width= "Fill_parent"
Wrap_content "
android:text=" Here are the details for the notification ... "/>
</LinearLayout>
Code in the 4.notificationview.java.
public class Notificationview extends activity {
@Override public
void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (r.layout.notification);
---Look up the Notification Manager service---
notificationmanager nm = (Notificationmanager) getsystemservice ( Notification_service);
---Cancel the notification that we started---
nm.cancel (getintent (). Getextras (). GetInt ("Notificationid"));
}
5. Code in the Androidmanifest.xml.
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= "Http://schemas.android.com/apk/res/androi"
D "package=" Net.learn2develop.Notifications "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "/> <uses-permission android:name=" Android.permission.VIBRAT E "/> <application android:icon=" @drawable/ic_launcher "android:label=" @string/app_ The name "> <activity android:label=" @string/app_name "Android:name=". Notificationsactivity "> <intent-filter > <action android:name=" android.in
Tent.action.MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/>" </intent-filter> </activity> <activity android:name= ". Notificationview "Android:label= "Details of notification" > <intent-filter> <action android:name= "Android."
Intent.action.MAIN "/> <category android:name=" Android.intent.category.DEFAULT "/>" </intent-filter> </activity> </application> </man Ifest>