Git Product home page Git Product logo

notificationdemo's Introduction

NotificationDemo

通知工具类,简化构造通知流程

GitHub主页

简介

  • 链式调用
  • 可自定义Notification Builder
  • 适配Android O
  • 可自定义NotificationChannel

调用

1、普通通知

NotificationUtils.with(mActivity)
                .setNotificationId(1)
                .setContentTitle("This is Common Title")
                .setContentText("This is Common Content")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(R.mipmap.ic_launcher)
                .setAutoCancel(true)
                .showNotify();

2、悬停通知

String title = "This is Stick Title";
String content = "This is Stick Content";
Intent intent = new Intent(mActivity,  MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(mActivity, 2,
        intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationUtils.with(mActivity)
        .setNotificationId(2)
        .setContentTitle(title)
        .setContentText(content)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setLargeIcon(R.mipmap.ic_launcher)
        .setTicker(title)
        .setAutoCancel(true)
        .setContentIntent(pendingIntent)
        .showNotify();

3、折叠通知

String title = "This is fold Title";
String content = "This is fold Content";
Intent intent = new Intent(mActivity,  MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(mActivity, 2,
        intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationUtils.with(mActivity)
        .setNotificationId(4)
        .setContentTitle(title)
        .setContentText(content)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setLargeIcon(R.mipmap.ic_launcher)
        .setTicker(title)
        .setAutoCancel(true)
        .setCustomContentView(R.layout.notify_collapsed)
        .setCustomBigContentView(R.layout.notify_show)
        .setContentViewListener(new NotificationUtils.ContentViewListener() {
            @Override
            public void onContentView(RemoteViews collapsed) {
                collapsed.setTextViewText(R.id.mTvTitle, "This IS custom title");
            }

            @Override
            public void onBigContentView(RemoteViews show) {

            }
        })
        .setContentIntent(pendingIntent)
        .showNotify();

4、tag通知

String title = "This is Tag Title";
        String content = "This is Tag Content";
        NotificationUtils.with(mActivity)
                .setNotificationId(3)
                .setContentTitle(title)
                .setContentText(content)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(R.mipmap.ic_launcher)
                .setTicker(title)
                .setNotificationTag(NotiTag)
                .setAutoCancel(true)
                .showNotify();

5、取消普通通知

 NotificationUtils.with(mActivity).removeNotification(notificationId);

6、取消tag通知

NotificationUtils.with(mActivity).removeNotiWithTag(3, NotiTag);

7、取消全部通知

NotificationUtils.with(mActivity).removeAll();

notificationdemo's People

Contributors

cyihui avatar

Stargazers

Henryzhu avatar

Watchers

 avatar

Forkers

lishiyou789

notificationdemo's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.