Use of the Android notification bar and android notification bar

Source: Internet
Author: User

Use of the Android notification bar and android notification bar

Key code and click event in which the app sends a notification message to the notification bar:

Package com. example. communications; import android. OS. bundle; import android. app. activity; import android. app. notification; import android. app. icationicationmanager; import android. app. pendingIntent; import android. content. context; import android. content. intent; import android. support. v4.app. notificationCompat; import android. view. menu; import android. view. view; public class MainActivity extends Activity {public Static final int notifi_id = 0x1; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main);} public void sendNotifi (View v) {icationicationcompat. builder builder = new NotificationCompat. builder (this); builder. setSmallIcon (R. drawable. ic_launcher); builder. setContentTitle ("You have a new message"); builder. setContentText ("Happy New Year! "); Builder. setTicker ("New message"); builder. setDefaults (Notification. DEFAULT_ALL); // builder. setAutoCancel (true); Intent intent = new Intent (this, Second. class); PendingIntent pi = PendingIntent. getActivity (this, 0, intent, PendingIntent. FLAG_UPDATE_CURRENT); builder. setContentIntent (pi); // builder. setOngoing (true); // resident Notification // create an object Notification n = builder. build (); // obtain the system's notification manager, and then send the notification NotificationManager nm = (icationicationmanager) getSystemService (Context. NOTIFICATION_SERVICE); nm. Y (notifi_id, n );}}

  

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.