Notification Bar Implementation

Source: Internet
Author: User

1, permissions, because to be deferred intention to make calls, so to configure a can call the permission

<uses-permission android:name= "Android.permission.CALL_PHONE"/>

2. code example

1  PackageCom.example.notifydemo;2 3 ImportAndroid.net.Uri;4 ImportAndroid.os.Build;5 ImportAndroid.os.Bundle;6 ImportAndroid.annotation.SuppressLint;7 ImportAndroid.annotation.TargetApi;8 Importandroid.app.Activity;9 Importandroid.app.Notification;Ten ImportAndroid.app.Notification.Builder; One ImportAndroid.app.NotificationManager; A Importandroid.app.PendingIntent; - Importandroid.content.Intent; - Importandroid.graphics.BitmapFactory; the ImportAndroid.view.Menu; - ImportAndroid.view.View; -  -  +  Public classMainactivityextendsActivity { -  + @Override A     protected voidonCreate (Bundle savedinstancestate) { at         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -     } -  -      -@SuppressLint ("Newapi") in      Public voidClick (View view) { -         //get a Notificationmanager obj toNotificationmanager nm =(Notificationmanager) Getsystemservice (notification_service); +         //icon, title, Time -Notification Notification =NewNotification (R.drawable.ic_launcher, "I am a Notification", System.currenttimemillis ()); theNotification.flags = Notification.flag_auto_cancel;//This flag bit setting indicates that the content of the notification bar is canceled after a click *         /*** * * Intent start*****/ $Intent Intent =NewIntent ();Panax Notoginseng intent.setaction (intent.action_call); -Intent.setdata (Uri.parse ("tel:110")); the         /*** * * Intent end*****/ +         //The second parameter is the request code, and the fourth one is the additional parameter APendingintent pendingintent = pendingintent.getactivity ( This, 0, intent, 0);//Deferred Intent theNotification.setlatesteventinfo ( This, "I am the title", "I am the text", pendingintent);//deferred Intent higher version can be null, lower version cannot be null +          -         //code that is only available after 3.0---start $         /*Notification.builder builder = new Builder (this); $ Builder.setcontenttitle ("I am Notification title") - . Setcontenttext ("I am notification content!") - . Setsmallicon (R.drawable.ic_launcher) the . Setlargeicon (Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher)); - Notification Notification = Builder.build ();*/Wuyi         //code that can be used after 3.0---end the          -         //The first parameter is an ID WuNm.notify (0, notification); -     } About  $}

Notification Bar Implementation

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.