android notification 理解

來源:互聯網
上載者:User

標籤:

notification簡單使用

1.不推薦 , 已不使用

 NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);    Notification notification = new Notification(R.drawable.ic_launcher, "This is ticker text", System.currentTimeMillis());    Intent intent = new Intent(this, NotificationActivity.class);    PendingIntent pi = PendingIntent.getActivity(this, 0, intent,    PendingIntent.FLAG_CANCEL_CURRENT);    //被刪除    notification.setLatestEventInfo(this, "This is content title","This is content text", pi);    manager.notify(1, notification);

 

   2.系統推薦
  

 NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);        Intent intent = new Intent(this, DD.class);        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);        Notification notification = new NotificationCompat.Builder(this)                .setSmallIcon(android.R.drawable.sym_def_app_icon)    //表徵圖                .setContentTitle("標題")                .setContentInfo("右下角")                .setContentText("內容")                .setAutoCancel(true)    //點擊一下就消失                .setContentIntent(pendingIntent)   //延遲意圖                .setTicker("剛出來是在手機最上方顯示,一會就消失")                .setWhen(System.currentTimeMillis())    //訊息的時間                .build();   //建立notification//        notification.flags = Notification.FLAG_AUTO_CANCEL;      跟setAutoCancel一樣作用        //顯示notification  第一個參數不能重複,否則就只能顯示重複的最後一個notification        manager.notify(1,notification);

 

3. 自訂notification
  

 RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.activity_main);    remoteViews.setImageViewResource(R.id.imageView,android.R.drawable.sym_def_app_icon);    remoteViews.setTextViewText(R.id.textText,"textview 的內容");    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);    Intent intent = new Intent(this, DD.class);    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);    Notification notification = new NotificationCompat.Builder(this)            .setAutoCancel(true)    //點擊一下就消失            .setContentIntent(pendingIntent)   //延遲意圖            .setContent(remoteViews)     //設定自訂的view            .build();    manager.notify(1,notification);

 

android notification 理解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.