简单的Android通知

来源:互联网 发布:84aaa最新域名升级 编辑:程序博客网 时间:2024/05/01 03:39
protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        btn=findViewById(R.id.mi);        btn.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                Notification .Builder no=new Notification.Builder(v.getContext());                no.setSmallIcon(R.drawable.icon);                no.setTicker("您有一条消息!");                no.setContentTitle("小米发来一条消息:");                no.setContentText("媳妇,早上吃了没?我现在在上班,嘻嘻��");                no.setDefaults(Notification.DEFAULT_ALL);                Intent intent=new Intent(Main.this,OneActivity.class);                PendingIntent pi=PendingIntent.getActivity(Main.this,1,intent,PendingIntent.FLAG_CANCEL_CURRENT);                no.setContentIntent(pi);                Notification n=no.build();                n.flags=Notification.FLAG_NO_CLEAR;                NotificationManager m=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);                m.notify((int) (Math.random() * 1000), n);            }        });    }

自己研究咯

原创粉丝点击