Android Notification??知詳解

來源:本網整理

這是因為android系統版本不同,它所采用的主題風格也不同,這個還是很好理解的。就像Button,在4.0和2.3兩個版本下就完全不同www.13333515.buzz防采集請勿采集本網。

<無詳細內??gt; scrolltotop.offset(100,120); scrolltotop.init();

[1].[代碼] [Java]代碼 跳至[1]

Android Notification通知詳解根據activity的生命周期,在activity不顯示時,會執行onStop函數(比如按下home??,所以你在onStop函數(按退出鍵除外)里面把notification放在通知欄里,再此顯示時,把notification從通知欄里去掉。或者,只要程序在運行就一直顯示通知欄圖標?? 下面對Notification類中的一些常量,字段,方法簡單介紹一下:常量??DEFAULT_ALL 使用所有默認值,比如聲音,震動,閃屏等等DEFAULT_LIGHTS 使用默認閃光提示DEFAULT_SOUNDS 使用默認提示聲音DEFAULT_VIBRATE 使用默認手機震動 【說明】:加入手機震動,一定要在manifest.xml中加入權限:<uses-permission android:name="android.permission.VIBRATE" />以上的效果常量可以疊??即通過notification.defaults =DEFAULT_SOUND|DEFAULT_VIBRATE; notification.defaults |= DEFAULT_SOUND (最好在真機上測試,震動效果模擬器上沒有) //設置flag??FLAG_AUTO_CANCEL 該通知能被狀態欄的清除按鈕給清除??FLAG_NO_CLEAR 該通知能被狀態欄的清除按鈕給清除??FLAG_ONGOING_EVENT 通知放置在正在運??FLAG_INSISTENT 是否一直進行,比如音樂一直播放,知道用戶響應 常用字段??contentIntent 設置PendingIntent對象,點擊時發送該Intentdefaults 添加默認效果flags 設置flag位,例如FLAG_NO_CLEAR??icon 設置圖標sound 設置聲音tickerText 顯示在狀態欄中的文字when 發送此通知的時間戳 NotificationManager常用方法介紹??public void cancelAll() 移除所有通知(只是針對當前Context下的Notification)public void cancel(int id) 移除標記為id的通知 (只是針對當前Context下的所有Notification)public void notify(String tag ,int id, Notification notification) 將通知加入狀態欄,標簽為tag,標記為idpublic void notify(int id, Notification notification) 將通知加入狀態欄,標記為id ?package com.ljq.activity; import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Intent;import android.graphics.Color;import android.os.Bundle; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); clearNotification(); } @Override protected void onStop() { showNotification(); super.onStop(); } @Override protected void onStart() { clearNotification(); super.onStart(); } /** * 在狀態欄顯示通知 */ private void showNotification(){ // 創建一個NotificationManager的引?? NotificationManager notificationManager = (NotificationManager) this.getSystemService(android.content.Context.NOTIFICATION_SERVICE); // 定義Notification的各種屬?? Notification notification =new Notification(R.drawable.icon, "督導系統", System.currentTimeMillis()); //FLAG_AUTO_CANCEL 該通知能被狀態欄的清除按鈕給清除?? //FLAG_NO_CLEAR 該通知不能被狀態欄的清除按鈕給清除?? //FLAG_ONGOING_EVENT 通知放置在正在運?? //FLAG_INSISTENT 是否一直進行,比如音樂一直播放,知道用戶響應 notification.flags |= Notification.FLAG_ONGOING_EVENT; // 將此通知放到通知欄的"Ongoing"??正在運行"組中 notification.flags |= Notification.FLAG_NO_CLEAR; // 表明在點擊了通知欄中??清除通知"后,此通知不清除,經常與FLAG_ONGOING_EVENT一起使?? notification.flags |= Notification.FLAG_SHOW_LIGHTS; //DEFAULT_ALL 使用所有默認值,比如聲音,震動,閃屏等等 //DEFAULT_LIGHTS 使用默認閃光提示 //DEFAULT_SOUNDS 使用默認提示聲音 //DEFAULT_VIBRATE 使用默認手機震動,需加上<uses-permission android:name="android.permission.VIBRATE" />權限 notification.defaults = Notification.DEFAULT_LIGHTS; //疊加效果常量 //notification.defaults=Notification.DEFAULT_LIGHTS|Notification.DEFAULT_SOUND; notification.ledARGB = Color.BLUE; notification.ledOnMS =5000; //閃光時間,毫?? // 設置通知的事件消?? CharSequence contentTitle ="督導系統標題"; // 通知欄標?? CharSequence contentText ="督導系統內容"; // 通知欄內?? Intent notificationIntent =new Intent(MainActivity.this, MainActivity.class); // 點擊該通知后要跳轉的Activity PendingIntent contentItent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(this, contentTitle, contentText, contentItent); // 把Notification傳遞給NotificationManager notificationManager.notify(0, notification); }? //刪除通知 private void clearNotification(){ // 啟動后刪除之前我們定義的通知 NotificationManager notificationManager = (NotificationManager) this .getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(0); }} SyntaxHighlighter.autoloader( 'applescript/js/sh309/scripts/shBrushAppleScript.js?t=1451961936000', 'actionscript3 as3/js/sh309/scripts/shBrushAS3.js?t=1451961936000', 'bash shell/js/sh309/scripts/shBrushBash.js?t=1451961936000', 'coldfusion cf/js/sh309/scripts/shBrushColdFusion.js?t=1451961936000', 'cpp c/js/sh309/scripts/shBrushCpp.js?t=1451961936000', 'obj-c objc/js/sh309/scripts/shBrushObjC.js?t=1451961936000', 'c# c-sharp csharp/js/sh309/scripts/shBrushCSharp.js?t=1451961936000', 'css/js/sh309/scripts/shBrushCss.js?t=1451961936000', 'delphi pascal/js/sh309/scripts/shBrushDelphi.js?t=1451961936000', 'diff patch pas/js/sh309/scripts/shBrushDiff.js?t=1451961936000', 'erl erlang/js/sh309/scripts/shBrushErlang.js?t=1451961936000', 'groovy/js/sh309/scripts/shBrushGroovy.js?t=1451961936000', 'haxe hx/js/sh309/scripts/shBrushHaxe.js?t=1451961936000', 'java/js/sh309/scripts/shBrushJava.js?t=1451961936000', 'jfx javafx/js/sh309/scripts/shBrushJavaFX.js?t=1451961936000', 'js jscript javascript/js/sh309/scripts/shBrushJScript.js?t=1451961936000', 'perl pl/js/sh309/scripts/shBrushPerl.js?t=1451961936000', 'php/js/sh309/scripts/shBrushPhp.js?t=1451961936000', 'text plain/js/sh309/scripts/shBrushPlain.js?t=1451961936000', 'py python/js/sh309/scripts/shBrushPython.js?t=1451961936000', 'ruby rails ror rb/js/sh309/scripts/shBrushRuby.js?t=1451961936000', 'scala/js/sh309/scripts/shBrushScala.js?t=1451961936000', 'sql/js/sh309/scripts/shBrushSql.js?t=1451961936000', 'vb vbnet/js/sh309/scripts/shBrushVb.js?t=1451961936000', 'xml xhtml xslt html/js/sh309/scripts/shBrushXml.js?t=1451961936000' ); SyntaxHighlighter.all();

騰訊的qq郵箱插件,猜測你是在android qq或者iphone qq里面看到的。如果你安裝了這個,那你就可以直接在里面看你的qq郵箱了,如果郵箱有新郵件,還會有通知提示內容來自www.13333515.buzz請勿采集。

免責聲明 - 關于我們 - 聯系我們 - 廣告聯系 - 友情鏈接 - 幫助中心 - 頻道導航
Copyright © 2017 www.13333515.buzz All Rights Reserved
3排列五开奖结果