自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android開發(fā)通知Notification

移動(dòng)開發(fā) Android
本文向大家介紹一下如何開發(fā)Android的系統(tǒng)有一個(gè)通知欄。通知是Android系統(tǒng)跟用戶交互的一個(gè)重要的部分。比如有新郵件,新短信息,未接來電等。

Android的系統(tǒng)有一個(gè)通知欄,這個(gè)通知欄很管用。通知是Android系統(tǒng)跟用戶交互的一個(gè)重要的部分。比如有新郵件,新短信息,未接來電等等信息都會(huì)顯示在通知欄。我們把通知欄拖下來,點(diǎn)擊通知信息,就能顯示通知的具體內(nèi)容。很cool的功能。

我們也可以定義通知的樣式,有圖標(biāo),通知的聲音,還有LED的顏色,閃爍的頻率等等。

我們看一下例子

 1: package com.halzhang.android.notification;
   2:  
   3: import android.app.Activity;
   4: import android.app.Notification;
   5: import android.app.NotificationManager;
   6: import android.app.PendingIntent;
   7: import android.content.Intent;
   8: import android.os.Bundle;
   9: import android.view.View;
  10: import android.widget.Button;
  11: /**
  12:  * 通知
  13:  * @author 張漢國
  14:  */
  15: public class NotificationDemo extends Activity {
  16:     /** Called when the activity is first created. */
  17:     //通知id
  18:     private static final int NOTICE_ID = 1222;
  19:     private Button notify;
  20:     private Button cancel;
  21:     @Override
  22:     public void onCreate(Bundle savedInstanceState) {
  23:         super.onCreate(savedInstanceState);
  24:         setContentView(R.layout.main);
  25:         notify = (Button) findViewById(R.id.noti);
  26:         cancel = (Button) findViewById(R.id.cancel);
  27:         notify.setOnClickListener(new View.OnClickListener() {
  28:             
  29:             @Override
  30:             public void onClick(View v) {
  31:                 notityMe();
  32:             }
  33:         });
  34:         
  35:         cancel.setOnClickListener(new View.OnClickListener() {
  36:             
  37:             @Override
  38:             public void onClick(View v) {
  39:                 final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  40:                 //取消通知
  41:                 manager.cancel(NOTICE_ID);
  42:             }
  43:         });
  44:     }
  45:     
  46:     private void notityMe(){
  47:         //獲得通知管理器,通知是一項(xiàng)系統(tǒng)服務(wù)
  48:         final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  49:         //初始化通知對(duì)象 p1:通知的圖標(biāo) p2:通知的狀態(tài)欄顯示的提示 p3:通知顯示的時(shí)間
  50:         Notification notification = new Notification(R.drawable.icon, "通知測(cè)試", System.currentTimeMillis());
  51:         //點(diǎn)擊通知后的Intent,此例子點(diǎn)擊后還是在當(dāng)前界面
  52:         PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, NotificationDemo.class), 0);
  53:         //設(shè)置通知信息
  54:         notification.setLatestEventInfo(this, "通知title", "通知信息內(nèi)容", intent);
  55:         //通知
  56:         manager.notify(NOTICE_ID, notification);
  57:     }
  58: }

【編輯推薦】

  1. Java創(chuàng)始人:Android只為競(jìng)爭(zhēng)不為錢
  2. Oracle控告Google:Android侵犯Java知識(shí)產(chǎn)權(quán)
  3. Google Go語言近況 Android平臺(tái)運(yùn)行加速
責(zé)任編輯:張攀 來源: cnblogs
相關(guān)推薦

2017-10-23 16:27:11

HTML5桌面Notificatio

2009-06-26 08:41:45

LinuxUbuntu通知機(jī)制

2011-07-27 14:37:33

iPhone Push Notif 服務(wù)器

2015-07-08 09:56:25

Notificatio多線程

2013-07-04 09:58:46

Android Pus信息推送

2017-04-10 18:34:16

AndroidNotificatio

2013-01-11 13:48:41

Android開發(fā)組件Notificatio

2011-12-22 10:33:39

PhoneGap APNotificatio

2013-06-20 11:04:46

iOS技巧NotificatioBadgeView

2013-04-25 15:15:41

Windows PhoWindows PhoWindows Pho

2011-07-25 18:07:29

iPhone Push Notificati

2012-06-14 10:08:18

2021-08-24 15:25:59

鴻蒙HarmonyOS應(yīng)用

2013-03-25 15:06:26

iOS通信模式

2012-06-20 09:58:23

Android 4.0通知系統(tǒng)

2021-04-25 07:28:37

谷歌Android 12 預(yù)覽 Beta 3

2023-11-19 23:19:09

2013-04-25 14:15:53

Windows PhoWindows PhoWindows Pho

2018-03-30 11:46:17

技術(shù)書籍

2022-03-10 09:00:37

提醒框ReactVue
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)