美文网首页
Android:Notifiction用法

Android:Notifiction用法

作者: 一米阳光给的温暖 | 来源:发表于2019-05-06 11:23 被阅读0次
    // MainActivity.java
    
    package com.example.administrator.notification;
    
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.support.v4.app.NotificationCompat;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            NotificationManager manager = (NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);
            Notification.Builder b = new Notification.Builder(this);
    
            b.setTicker("支付宝到账一百万元");
            b.setSmallIcon(R.mipmap.ic_launcher);
            b.setContentText("通知内容");
            b.setContentTitle("通知标题");
            manager.notify(1,b.getNotification());
    
            NotificationCompat.Builder b1 = new NotificationCompat.Builder(this);
            b1.setContentTitle("通知标题");
            b1.setContentText("通知内容");
            b1.setSmallIcon(R.mipmap.ic_launcher);
            b1.setTicker("通知的提示消息");
            manager.notify(2,b1.build());
        }
    }
    
    

    相关文章

      网友评论

          本文标题:Android:Notifiction用法

          本文链接:https://www.haomeiwen.com/subject/fqkroqtx.html