Android development tool Class 16_notificationactivity

Source: Internet
Author: User

Activity that runs in the foreground can send a message to the user via dialog, Toast, a program that runs later, such as a Service application such as downloading, receiving information, and then using Notification (notification) to send a message to the user.

1 Importandroid.app.Activity;2 Importandroid.app.Notification;3 ImportAndroid.app.NotificationManager;4 Importandroid.app.PendingIntent;5 ImportAndroid.content.Context;6 Importandroid.content.Intent;7 ImportAndroid.os.Bundle;8 ImportAndroid.view.View;9 ImportAndroid.view.View.OnClickListener;Ten ImportAndroid.widget.Button; One Importandroid.widget.RemoteViews; A  -  Public classNotificationactivityextendsActivity { -      the Button B1; - Notificationmanager Nmanager; - Notification Notification; -     intNotificationid=1; +      - @Override +     protected voidonCreate (Bundle savedinstancestate) { A         Super. OnCreate (savedinstancestate); at          - Setcontentview (r.layout.notificationlayout); -b1=(Button) Findviewbyid (R.ID.NOTIFICATION_BT1); -B1.setonclicklistener (NewOnclicklistener () { - @Override -              Public voidOnClick (View v) { in                 //sendnotification (); - sendcustomnotification (); to             }} +         ); -     } the      *     //Send custom Notifications $      Public voidsendcustomnotification () {Panax Notoginseng         //1. Get Notificationmanager -Nmanager=(Notificationmanager) Getsystemservice (context.notification_service); the         //2. Create Notification +notification =NewNotification ( A R.drawable.folder_open, the"Received file", + System.currenttimemillis () -             ); $Remoteviews RV =Newremoteviews (Getpackagename (), r.layout.notificationinterfacelayout); $ Rv.setimageviewresource (r.id.notification_img, r.drawable.savefile); -Rv.settextviewtext (R.id.notification_title, "Lullaby. mp3"); -Rv.setprogressbar (R.id.notification_progressbar, 100, 20,false); thenotification.contentview=RV; -         //3. Set the properties, which are displayed after the status bar is expandedWuyiIntent Intent =NewIntent ( This, Toastactivity.class);//turn to other theIntent.setflags (intent.flag_activity_clear_top|intent.flag_activity_new_task);  -Pendingintent pintent=pendingintent.getactivity ( This, 0, intent, 0); WuNotification.contentintent=pintent; -         //4. Send notification to manager AboutNmanager.notify (notificationid++, notification); $     } -      -     //Send Notifications -      Public voidsendnotification () { A         //1. Get Notificationmanager +Nmanager=(Notificationmanager) Getsystemservice (context.notification_service); the         //2. Create Notification -notification =NewNotification ( $ R.drawable.folder_open, the"Received file", the System.currenttimemillis () the             ); the         //Optional Properties -notification.defaults|=Notification.default_sound; inNotification.flags |=notification.flag_insistent; the          the          About         //3. Set the properties, which are displayed after the status bar is expanded theIntent Intent =NewIntent ( This, Toastactivity.class);//turn to other theIntent.setflags (intent.flag_activity_clear_top|intent.flag_activity_new_task);  thePendingintent pintent=pendingintent.getactivity ( This, 0, intent, 0); +Notification.setlatesteventinfo ( This, "Receive file", "File already download complete", pintent); -         //4. Send Notification to Manager theNmanager.notify (notificationid++, notification);Bayi     } the      the}

Android development tool Class 16_notificationactivity

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.