android開發通知常用設定方法

來源:互聯網
上載者:User

標籤:

簡單記錄 通知上的設定方法,沒有樣本

 //進度 通知            notificationManager = (NotificationManager)                    context.getSystemService(Context.NOTIFICATION_SERVICE);            builder = new NotificationCompat.Builder(context);            builder.setContentTitle("新版本")//顯示的標題                    .setContentText("正在下載...")//顯示的詳細內容                    .setSmallIcon(R.mipmap.ic_launcher);            //提示文字            builder.setTicker("您有新訊息!");            //點擊取消,優先順序            builder.setAutoCancel(true).                    setPriority(NotificationCompat.PRIORITY_DEFAULT);            builder.setDefaults(Notification.DEFAULT_ALL);            // 關聯PendingIntent,點擊跳轉的頁面            //PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,            // new Intent(this, MainActivity.class), 0);            //builder.setContentIntent();            //指定視圖Notification 正常狀態下的視圖            // builder.build().contentView=contentView;            //展開時的視圖            //builder.build().bigContentView = expandView;              /*提示方式            DEFAULT_ALL:鈴聲、閃光、震動均系統預設。            DEFAULT_SOUND:系統預設鈴聲。            DEFAULT_VIBRATE:系統預設震動。            DEFAULT_LIGHTS:系統預設閃光。            其他方式:            setSound(Uri sound):設定一個鈴聲,用於在通知的時候響應。            傳遞一個Uri的參數,格式為“file:///mnt/sdcard/Xxx.mp3”。            setLights(int argb, int onMs, int offMs):設定前置LED燈的游標閃爍頻率,            持續毫秒數,停頓毫秒數。            setVibrate(long[] pattern):設定震動的模式,以一個long數組儲存毫秒級間隔的震動。            */            /*            setStyle()傳遞一個NotificationCompat.Style對象,它是一個抽象類別,            Android為我們提供了三個實作類別,用於顯示不同的情境。分別是:            NotificationCompat.BigPictureStyle, 在細節部分顯示一個256dp高度的位元影像。            NotificationCompat.BigTextStyle,在細節部分顯示一個大的文字區塊。            NotificationCompat.InboxStyle,在細節部分顯示一段行文本。*/            //builder.setWhen();//設定通知的時間,預設目前時間

發送通知:

 //更新進度            builder.setProgress((int) l, (int) l1, true);            //發送通知            notificationManager.notify(notificationFlag, builder.build());
取消通知:

 notificationManager.cancel(notificationFlag);


android開發通知常用設定方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.