Android多媒体(一)

来源:互联网 发布:linux php log日志 编辑:程序博客网 时间:2024/05/06 08:49

一、通知(Notification)

1.获得NotificationManager2.获取Notification3.设置Notification属性;4.设置PendingIntent:点击通知跳转;5.显示通知manager.notify(int id, Notification notification);
例:    private void showNotify() {        NotificationManager manager = (NotificationManager)  getSystemService(NOTIFICATION_SERVICE);        Notification.Builder builder = new Notification.Builder(MainActivity.this);        builder.setSmallIcon(R.mipmap.ic_launcher);        builder.setTicker("my'notify");        builder.setContentTitle("this is title");        builder.setContentText("this is content");        Intent intent = new Intent(MainActivity.this, NotifiActivity.class);        PendingIntent pendingIntent = PendingIntent.getActivity(this ,0, intent, PendingIntent.FLAG_CANCEL_CURRENT);        builder.setContentIntent(pendingIntent);        Notification notification = builder.build();        notification.defaults = Notification.DEFAULT_ALL;        manager.notify(1, notification);    }
△点击Notification之后消失:  NotificationManager manager = (NotificationManager)            getSystemService(NOTIFICATION_SERVICE);    manager.cancel(1); //参数为notityId;
0 0