ANDROID NOTIFICATIONCOMPAT Notification message

Source: Internet
Author: User

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

Related Article

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.