ANDROID Info Notification Bar message notification

Source: Internet
Author: User

Notification is the message tip at the top of the Android phone

Here we set two buttons respectively, to achieve the top of the message send and cancel

function implementation

The first thing to do is to set up a notification control class in the main activity

Notificationmanager Manager; Notification Control class

Then get the system service in the OnCreate method

Manager  = (notificationmanager) getsystemservice (Context.notification_service);

Then set the notification bar information

private void SendNotification () {        Intent Intent = new Intent (this,mainactivity.class);        Pendingintent pintent = pendingintent.getactivity (this,0,intent,0);        Builder builder = new Builder (this);        Builder.setsmallicon (R.mipmap.ic_launcher);//Set icon        builder.setticker ("Hello");//Set phone status bar prompt        Builder.setwhen (System.currenttimemillis ());//Time        Builder.setcontenttitle ("Notification notification Bar");//title        Builder.setcontenttext ("I am Little Hao");//notification content        builder.setcontentintent (pintent);//Click after the intent        builder.setdefaults ( Notification.default_all);//give notice to set the vibration, sound, and hint light three kinds of effects, but remember to apply for permission        Notification Notification = Builder.build (); Above 4.1 versions Use this method        //builder.getnotification ();   Version 4.1 follows this method        manager.notify (notification_id,notification);    }

Add vibration and Cue light permissions to the Mainfest file

<uses-permission android:name= "Android.permission.VIBRATE" ></uses-permission>   < Uses-permission android:name= "Android.permission.FLASHLIGHT" ></uses-permission>

ANDROID Info Notification Bar message notification

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.