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