Import android.os.bundle;import android.app.activity;import android.app.notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.context;import android.content.intent;import android.graphics.bitmap;import android.graphics.bitmapfactory;import android.support.v4.app.notificationcompat;import android.view.view;public class mainactivity extends activity { @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview (R.layout.activity_main); } public void click (VIEW V) { Notificationcompat.builder builder = &nBsp; new notificationcompat.builder (This ); //Set title Builder.setcontenttitle ("notification title"); builder.setcontenttext ("This is the content .....") "); //icons Builder.setsmallicon (R.drawable.ic_launcher); //is the notice opened before, Page can see the hint text builder.setticker ("flash, search"); /** * set the style of notification */ //notification of large text types notificationcompat.bigtextstyle big = new notificationcompat.bigtextstyle (); big.setbigcontenttitle ("big title"). BigText ("Big content"); //Setting the builder style //builder.setstyle (big); //the type of big picture notificationcompat.bigpicturestyle bigimg = new notificationcompat.bigpicturestyle (); bitmap b = bitmapfactory.decoderesource (GetResources (), R.drawable.ic_launcher); bigimg.biglargEIcon (b); //set style //builder.setstyle (bigimg); /** * can show more text */ NotificationCompat.InboxStyle inboxStyle = new Notificationcompat.inboxstyle (); inboxstyle.addline ("One line of text"); inboxstyle.addline ("2 lines of text"); inboxstyle.addline ("3 Lines of text"); Inboxstyle.addline ("4 Lines of text"); inboxstyle.addline ("5 Lines of text"); builder.setstyle (Inboxstyle); /** * set jump, pre-jump. Not a little bit * */ intent intent = new intent ( This,mainactivity.class); /** * * pendingintent: Encapsulates the pre-intent of the intent, indicating that the * action has not yet occurred, but will retain this action * context Context * requestcode: Request Code * intent &NBSP: Jump Intent * flag: Tag */ pendingintent pendingintent = pendingintent.getactivity (this, 200, intent, Pendingintent.flag_one_shot); //PendingIntent.FLAG_NO_CREATE; general use of a Builder.setcontentintent (pendingintent); //Service to invoke /** * get is a system of services * Transfer context.notification_service Can get a manager for managing notification * */ notificationmanager manager = (Notificationmanager) Getsystemservice (Context.notification_service); /** * builder constructor, can build yo notification object * */ notification build = builder.build (); /** * This method can issue a notification * id ID number of the unique ID * * notification is the object that needs to be notified, (who needs this notice) */ manager.notify (1, build); }}
ANDROID NOTIFICATIONCOMPAT Notification message