国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Android - Android中關于Notification及NotificationManger的詳解

Android中關于Notification及NotificationManger的詳解

2021-01-10 14:26Android開發網 Android

本篇文章小編為大家介紹,Android中關于Notification及NotificationManger的詳解。需要的朋友參考下

Android狀態欄提醒

在Android中提醒功能也可以用AlertDialog,但是我們要慎重的使用,因為當使用AlertDialog的時候,用戶正在進行的操作將會被打斷,因為當前焦點被AlertDialog得到。我們可以想像一下,當用戶打游戲正爽的時候,這時候來了一條短信。如果這時候短信用AlertDialog提醒,用戶必須先去處理這條提醒,從而才能繼續游戲。用戶可能會活活被氣死。而使用Notification就不會帶來這些麻煩事,用戶完全可以打完游戲再去看這條短信。所以在開發中應根據實際需求,選擇合適的控件。

步驟:

一、添加布局對象

復制代碼 代碼如下:


<Button
android:id="@+id/showButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="showNotification" />

 

<Button
android:id="@+id/cancelButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="cancelNotification" />


二、修改MianActivity繼承處Activity并實現接口OnClickListener

復制代碼 代碼如下:


public class MainActivity extends Activity implements OnClickListener {
 private Context mContext = this;
 private Button showbtn, calclebtn;
 private Notification noti;
 private NotificationManager notiManger;
 private static int NOTIFICATION_ID = 0x0001;

 

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  setUpViews();
 }

 private void setUpViews() {
  showbtn = (Button) findViewById(R.id.showButton);
  calclebtn = (Button) findViewById(R.id.cancelButton);
  noti = new Notification(R.drawable.ic_launcher, "this is a notification", System.currentTimeMillis());
  noti.defaults = Notification.DEFAULT_SOUND;// 使用默認的提示聲音
  noti.defaults |= Notification.DEFAULT_VIBRATE;// 添加震動
  notiManger = (NotificationManager) this.getSystemService(mContext.NOTIFICATION_SERVICE);//獲取NofificationManger對象
  showbtn.setOnClickListener(this);//讓Activity實現接口OnClickListener可以簡單的通過此兩行代碼添加按鈕點擊響應事件
  calclebtn.setOnClickListener(this);
 }

 // 按鈕點擊事件響應
 @Override
 public void onClick(View v) {
  if (v == showbtn) {
   Intent intent = new Intent(this.getApplicationContext(),this.getClass());
   // 設置Intent.FLAG_ACTIVITY_NEW_TASK
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
   // noti.setLatestEventInfo(context, contentTitle, contentText, contentIntent)設置(上下文,標題,內容,PendingInteng)
   noti.setLatestEventInfo(this, "10086", "你從此以后免除所有話費", contentIntent);
   // 發送通知(消息ID,通知對象)
   notiManger.notify(NOTIFICATION_ID, noti);
  } else if (v == calclebtn) {
   // 取消通知(id)
   notiManger.cancel(NOTIFICATION_ID);
  }
 }
}

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲一区二区在线看 | 精品无码久久久久国产 | 在线观看特色大片免费网站 | 一区二区三区www. | 综合色爱| 欧美中文字幕一区二区 | 成人精品一区二区三区中文字幕 | sese综合| 国产精品午夜电影 | 一级特黄bbbbb免费观看 | 国产成人免费在线 | 伊人最新网址 | 精品少妇一区二区三区日产乱码 | 欧美 日韩 中文 | 国产精品美女 | 欧美日韩国产影院 | 亚洲va欧美va天堂v国产综合 | 日韩精品 电影一区 亚洲 | 欧美一级在线视频 | 香蕉成人啪国产精品视频综合网 | 成人在线视频网站 | 在线观看亚洲 | 黄色免费av| 欧美福利视频 | 国产一区二区三区撒尿在线 | 国内外成人在线视频 | 伊人一区二区三区 | 中文一二区 | 国产一区二区在线视频 | 久久天天 | 精品无码久久久久国产 | 毛片久久久 | 精品久久久久久久久久 | 欧美成人免费 | 日韩在线精品视频 | 久久久久成人精品 | 偷拍一区二区三区 | 久久不卡| 国产成人一区二区三区 | 亚洲成av人片一区二区梦乃 | 欧美精品在线一区二区三区 |