A powerful library for creating notifications in android platform.

Overview

Android Arsenal Maven Central Build Status Coverage Status Join the chat at https://gitter.im/halysongoncalves/pugnotification

soon

Download

Download the latest AAR or grab via Maven:

<dependency>
  <groupId>com.github.halysongoncalves</groupId>
  <artifactId>pugnotification</artifactId>
  <version>1.8.1</version>
</dependency>

or Gradle:

compile 'com.github.halysongoncalves:pugnotification:1.8.1'

Introduction

Screenshots

You're probably tired of writing code to display notifications in your applications, the library abstracts all the notifications construction process for you in a single line of code. Magic? Lie? I summarize in: productivity. To further improve productivity, pugnotification from release 1.2.0 now has support Android Wear.

PugNotification.with(context)
    .load()
    .identifier(identifier)
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .smallIcon(smallIcon)
    .largeIcon(largeIcon)
    .flags(Notification.DEFAULT_ALL)
    .button(icon, title, pendingIntent)
    .click(cctivity, bundle)
    .dismiss(activity, bundle)
    .color(color)
    .ticker(ticker)
    .when(when)
    .vibrate(vibrate)
    .lights(color, ledOnMs, ledOfMs)
    .sound(sound) 
    .autoCancel(autoCancel)
    .simple()
    .build();

Many common pitfalls in building cases are handled automatically by PugNotification:

Custom Notifications depend on RemoteViews and Android has RemoteView support for Api's below Jelly Bean. Notifications without no messages and title does not make sense there. In addition to these treatments, there are other held by Picasso Library Square:

Handling ImageView recycling and download cancelation in an adapter. Complex image transformations with minimal memory use. Automatic memory and disk caching.

Simple Notification

Simple notification with just text and message.

PugNotification.with(context)
    .load()
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .largeIcon(R.drawable.pugnotification_ic_launcher)
    .flags(Notification.DEFAULT_ALL)
    .simple()
    .build();

Progress Notification

Simple notification with progress.

PugNotification.with(context)
    .load()
    .identifier(identifier)
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .progress()
    .value(progress,max, indeterminate)
    .build();
PugNotification.with(context)
    .load()
    .identifier(identifier)
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .progress()
    .update(identifier,progress,max, indeterminate)
    .build();

Custom Notification

We have changed the way the library handles the download images for custom notifications. Previously disrespectfully because of the Picasso library. But many users were asking for the option of being able to choose how to download the image. So we serve the requests and modify the library to allow the download of image management as an example:

PugNotification.with(context)
    .load()
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .largeIcon(R.drawable.pugnotification_ic_launcher)
    .flags(Notification.DEFAULT_ALL)
    .color(android.R.color.background_dark)
    .custom()
    .background(url)
    .setImageLoader(Callback)
    .setPlaceholder(R.drawable.pugnotification_ic_placeholder)
    .build();  

Wear Notification

PugNotification from release 1.2.0 started to support all types of notifications to Android Wear. We try to anticipate us to make life easier for developers to develop applications for wearable.

PugNotification.with(mContext).load()
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .autoCancel(true)
    .largeIcon(R.drawable.pugnotification_ic_launcher)
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .flags(Notification.DEFAULT_ALL)
    .wear()
    .background(Bitmap)
    .setRemoteInput(icon, title, pendingIntent, remoteInput)
    .setPages(List<Notification> listNotification)
    .setHideIcon(Boolean)
    .build();

What's New

*1.8.1

Fix Message Spanned length check

*1.8.0

Adding method for cancellation in tag-based notifications. And added validation to ensure that the color assigned in the method is @ColorRes.

*1.7.0

Added a new type of notification, progress. Now you can assign the basic features of a notification, while also adding a progressbar in the notification.

It was also added new method: ongoing (). With it possible to make false removing the notification.

*1.6.0

Fixed bug that did not allow the award of a sound and made some organizations and otimizaçnoes the code.

Now it is necessary to set one of the flag's: Notification.DEFAULT_ALL, Notification.DEFAULT_SOUND, Notification.DEFAULT_VIBRATE or Notification.DEFAULT_LIGHTS

*1.5.0

Method has been added that allows informing the existing configuration of the default notice. By default it is already configured with Notification.DEFAULT_ALL if you want to change just inform the new configuration in the defaults method (int defaults).

*1.4.0

Now just the client implement the ImageLoader interface and implement a way to manage the download of the image. Below we use the Picasso:

    @Override
    public void load(String uri, final OnImageLoadingCompleted onCompleted) {
        viewTarget = getViewTarget(onCompleted);
        Picasso.with(this).load(uri).into(viewTarget);
    }
    
    private static Target getViewTarget(final OnImageLoadingCompleted onCompleted) {
        return new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                onCompleted.imageLoadingCompleted(bitmap);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            }
        };
    }

PugNotification supports placeholders if download the image in the background is not successful. The library already have a default placeholder size 622x384.

ProGuard

If you use the Picasso to manage the download of the image, add the line below to your proguard file:

-dontwarn com.squareup.okhttp.**

Contributing

If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request.

When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. Please also make sure your code compiles by running gradlew clean and gradlew assemble.

License

Copyright 2013 Halyson L. Gonçalves, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Image problem: drawable-nodpi\pugnotification_ic_placeholder.png

    Image problem: drawable-nodpi\pugnotification_ic_placeholder.png

    AAPT err(Facade for 1388311168): D:\Test\app\build\intermediates\exploded-aar\com.github.halysongoncalves\pugnotification\1.8.0\res\drawable-nodpi\pugnotification_ic_placeholder.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited.

    DONE 
    opened by hateum 5
  • Can I add FLAG_NO_CLEAR

    Can I add FLAG_NO_CLEAR

    Can I write this with pugnotification library ?

    Notification noti = new NotificationCompat.Builder(this).setContentTitle("Title").setSmallIcon(R.drawable.icon).build();
    noti.flags |= Notification.FLAG_NO_CLEAR;
    nm.notify(MAIN_NOTIFICATION, noti);
    
    DONE 
    opened by sytolk 5
  • Making an option to not use large icon in PugNotification

    Making an option to not use large icon in PugNotification

    Not setting a default LargeIcon, to make an option to use or not use a large icon in notification. Otherwise I'll get an Android icon (R.drawable.pugnotification_ic_launcher) plus smallIcon in notification.

    I tested it in Sample App and it works. Just comment .largeIcon() line in PugNotification builder to test.

    Review on Reviewable

    DONE 
    opened by burnermanx 5
  • Allow library to load large icon bitmap

    Allow library to load large icon bitmap

    What do you think about having the library taken care of the bitmap decoding for the large icon ?

    I was thinking that maybe you can overload the method, something like the following:

    public class Load {
    
        // Current method
        public Load largeIcon(Bitmap bitmap ) {
          ...
        }
    
        // New method
        public Load largeIcon(int largeIcon) {
            if (largeIcon <= 0) {
                throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
            }
            Bitmap bitmap = BitmapFactory.decodeResource( 
                   mNotification.mContext.getResources(), largeIcon )
            this.mBuilder.setLargeIcon(bitmap);
            return this;
        }
    

    Would you take a PR for this ?

    DONE 
    opened by robertoestivill 5
  • Buttons not showing in custom notification

    Buttons not showing in custom notification

    This works fine and show the buttons: PugNotification.with(this) .load() .title(...) .message(...) .smallIcon(...) .largeIcon(..) .button(...), .button(...) .simple() .build();

    This doesn't: PugNotification.with(this) .load() .title(...) .message(...) .smallIcon(...) .largeIcon(..) .button(...), .button(...) .custom() .build();

    BACKLOG 
    opened by Shailevy 4
  • Add additional flags to Simple

    Add additional flags to Simple

    You can write

    FlagNotification.with(this).load()
                    .identifier(MAIN_NOTIFICATION)
                    .smallIcon(R.drawable.icon)
                    .autoCancel(false)
                    .largeIcon(R.drawable.icon)
                    .title("Title")
                    .simple()
                    .build(Notification.FLAG_NO_CLEAR);
    
    

    Review on Reviewable

    DONE 
    opened by sytolk 3
  • Is it possible to use an image loading library other than Picasso ?

    Is it possible to use an image loading library other than Picasso ?

    I'm using UIL in my application, and I don't want to add Picasso as a dependency.

    Perhaps it is a good idea to add an interface for customizing the image loading operations ?

    Something like

    interface ImageLoader {
          public void load(String url, Drawable placeholder, Notification target);
    }
    
    DONE 
    opened by R4md4c 3
  • start a service on click

    start a service on click

    When passing activity to click it works without an issue, but if I pass an service class to it, it just doesn't fire.

    Any ideas?

    here's my code:

    
    PugNotification.with(this)
                    .load()
                    .largeIcon(R.drawable.ic_notif)
                    .smallIcon(R.drawable.ic_notif_small)
                    .title("Start Service")
                    .message("in background")
                    .click(MyService.class)
                    .simple()
                    .build();
    

    Manifest:

    
    <service
                android:name=".MyService"
                android:enabled="true"
                android:exported="true"/>
    
    DONE 
    opened by eboye 2
  • Notification Progress for indeterminate progress

    Notification Progress for indeterminate progress

    Is there any way to have a progress notification with an indeterminate progress? Something which just says loading with an google indeterminate progressbar as below?

    https://github.com/DreaminginCodeZH/MaterialProgressBar

    DONE 
    opened by GeorgeChackungal 2
  • Fix messageSpanned length check

    Fix messageSpanned length check

    When you pass a messageSpanned, the method checks message member and not the messageSpanned parameter which is not correct and causes null pointer exception

    Review on Reviewable

    DONE 
    opened by aminelaadhari 2
  • Fix messageSpanned length check

    Fix messageSpanned length check

    When you pass a messageSpanned, the method checks message member and not the messageSpanned parameter which is not correct and causes null pointer exception

    Review on Reviewable

    opened by aminelaadhari 2
  • Is this library still managed ?

    Is this library still managed ?

    I have seen lots of issues regarding Oreo channel integration using PugNotification , so is it working , i am considering to use this in my production app

    opened by Zulqurnain 1
  • java.lang.IllegalStateException: Method call should happen from the main thread

    java.lang.IllegalStateException: Method call should happen from the main thread

    I am trying the following code to show Custom Notification but the app is crashing giving java.lang.IllegalStateException: Method call should happen from the main thread.

    PendingIntent pendingIntent;
            String url = data.get(CommonConsts.NOTIFICATION_KEY_URL);
            String thumbUrl = data.get(CommonConsts.THUMB_URL_KEY);
    
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    
            // Use TaskStackBuilder to build the back stack and get the PendingIntent
            pendingIntent =
                    TaskStackBuilder.create(this)
                            // add all of DetailsActivity's parents to the stack,
                            // followed by DetailsActivity itself
                            .addNextIntentWithParentStack(browserIntent)
                            .getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
    
            Custom mLoad = null;
            if (pendingIntent != null) {
                mLoad = PugNotification.with(getBaseContext()).load()
                        .smallIcon(R.mipmap.ic_launcher)
                        .autoCancel(true)
                        .largeIcon(R.mipmap.ic_launcher)
                        .title(title == null ? this.getString(R.string.app_name) +
                                " Alert" : title)
                        .message(messageBody)
                        .bigTextStyle(messageBody, messageBody)
                        .priority(Notification.PRIORITY_MAX)
                        .flags(Notification.DEFAULT_ALL)
                        .when(1)
                        .button(R.drawable.ic_chrome_reader_mode_black_18dp, getString(R.string.read_more), pendingIntent)
                        .click(pendingIntent)
                        .custom()
                        .setImageLoader(new ImageLoader() {
                            @Override
                            public void load(String uri, OnImageLoadingCompleted onCompleted) {
                                viewTarget = getViewTarget(onCompleted);
                                Picasso.with(getBaseContext()).load(uri).into(viewTarget);
                            }
    
                            @Override
                            public void load(int imageResId, OnImageLoadingCompleted onCompleted) {
    
                            }
                        })
                        .setPlaceholder(R.drawable.pugnotification_ic_placeholder)
                        .background(thumbUrl);
            }
    
            if (mLoad != null) {
                mLoad.build();
            }
    
    Complete Exception:
    Process: psl99.com.pakistan_super_league, PID: 19021
    java.lang.IllegalStateException: Method call should happen from the main thread. at br.com.goncalves.pugnotification.notification.Custom.build(Custom.java:119) at psl99.com.pakistan_super_league.services.MyFirebaseMessagingService.showNewsArticleNotification(MyFirebaseMessagingService.java:276) at psl99.com.pakistan_super_league.services.MyFirebaseMessagingService.sendNotification(MyFirebaseMessagingService.java:150)
    atpsl99.com.pakistan_super_league.services.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:111)
    at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(Unknown Source)
    at com.google.firebase.iid.zzc.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:762)
    
    opened by Shajeel-Afzal 0
  • Image Loading with Glide

    Image Loading with Glide

    Thanks for creating this awesome Library for showing Push Notifications. Can you please tell us how to use Glide with this library instead of Picasso?

    Regards

    • Shajeel
    opened by Shajeel-Afzal 0
  • Vibrate with prefrence Screen

    Vibrate with prefrence Screen

    hi i set a setting with a boolean on it means notiffication have vibrate and off it means vibrate is off but its not working on vibrate off this is my code public class AlarmReceiver extends BroadcastReceiver { long[] vibrate; @Override public void onReceive(Context context, Intent intent) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); String alarm = pref.getString("key_notifications_new_message_ringtone","default ringtone"); Uri uri = Uri.parse(alarm); boolean vibre = pref.getBoolean("key_vibrate",false); if (vibre){ vibrate = new long[] {200,700}; }else { vibrate = new long[] {0,0}; } { Bundle bundle = intent.getExtras(); String name = bundle.getString("name"); String id = bundle.getString("tourId"); PugNotification.with(context) .load() .title("name") .message("id") .bigTextStyle("bigtext") .smallIcon(R.drawable.pugnotification_ic_launcher) .largeIcon(R.drawable.pugnotification_ic_launcher) .sound(uri) .autoCancel(true) .vibrate(vibrate) .simple() .build(); } } and this is the error i just want to off the vibrate with this switch java.lang.RuntimeException: Unable to start receiver app.mma.PokerInfo.exTourList.AlarmReceiver: java.lang.IllegalArgumentException: Vibrate Time 0 Invalid!

    opened by osairon 0
Owner
Halyson Lima Gonçalves
Graduated in Information Systems from UFV (Federal University of Viçosa), I have more than 8 years of experience in Mobile Development.
Halyson Lima Gonçalves
A library to receive and show notification for Android.

Basalam Notification A library to receive and show notiffication for Android. Register or unregister user to your server. Receive Notifictation per 15

Basalam 23 Dec 14, 2022
An Android library for simple notification displayed inside ViewGroup instead of system.

SimpleNotificationBar SimpleNotificationBar is an Android library that helps developers to easily create a Notification inside a view group, instead o

Tristan Le 2 Jul 29, 2022
Android Real Time Chat & Messaging SDK

Android Chat SDK Overview Applozic brings real-time engagement with chat, video, and voice to your web, mobile, and conversational apps. We power emer

Applozic 659 May 14, 2022
Kommunicate.io Android Chat SDK for Customer Support

Kommunicate Android Chat SDK for Customer Support An Open Source Android Live Chat SDK for Customer Support Overview Kommunicate provides open source

Kommunicate 68 Jan 3, 2023
Android has a built in microphone through which you can capture audio and store it , or play it in your phone. There are many ways to do that but with this dialog you can do all thats with only one dialog.

# Media Recorder Dialog ![](https://img.shields.io/badge/Platform-Android-brightgreen.svg) ![](https://img.shields.io/badge/Android-CustomView-blue.sv

Abdullah Alhazmy 73 Nov 29, 2022
Conversations is an open source XMPP/Jabber client for Android

Conversations Conversations: the very last word in instant messaging Design principles Be as beautiful and easy to use as possible without sacrificing

Daniel Gultsch 4.2k Dec 30, 2022
Email-based instant messaging for Android.

Delta Chat Android Client This is the Android client for Delta Chat. It is available on F-Droid and the Google Play Store. The APK can also be downloa

Delta Chat 897 Jan 2, 2023
A glossy Matrix collaboration client for Android.

Element Android Element Android is an Android Matrix Client provided by Element. It is a total rewrite of Riot-Android with a new user experience. Nig

Element (formerly New Vector) 2.6k Dec 30, 2022
The most beautiful SMS messenger for Android

QKSMS QKSMS is an open source replacement to the stock messaging app on Android. It is currently available on the Google Play Store and on F-Droid Rep

Moez Bhatti 3.9k Dec 30, 2022
Unofficial, FOSS-friendly fork of the original Telegram client for Android

or 1McafEgMvqAVujNLtcJumZHxp2UfaNByqs Telegram-FOSS Telegram is a messaging app with a focus on speed and security. It’s superfast, simple and free. T

null 2k Jan 1, 2023
Official Android client for the Kontalk messaging system

This is the official Android client for the Kontalk messaging system. It always implements the latest protocol.

Kontalk 563 Dec 24, 2022
Open Source Messenger App For Android - Real-time Messaging, Voice and Video Calls

Open Source Messenger App For Android - Real-time Messaging, Voice and Video Calls

mesibo 630 Dec 7, 2022
Sample Android App for WebRTC with Firebase as backend

Simple Demo App for Android WebRTC video call using Firebase Realtime Database as Signalling server.

Devesh Chaudhari 19 Dec 17, 2022
A hybrid chat android application based on the features of Instagram and Whatsapp having UI just as Telegram.

A hybrid chat android application based on the features of Instagram and Whatsapp having UI just as Telegram.

Ratik Tiwari 1 May 22, 2022
A private-chat-only Android App for Secure Scuttlebutt

Tremola README Tremola is a Secure Scuttlebutt (SSB) client for Android that only supports private chat. Tremola aims at having the same functionality

Computer Networks Group 29 Oct 30, 2022
💙 Android sample Avengers chat application using Stream Chat SDK based on MVVM (ViewModel, Coroutines, Room, Hilt, Repository) architecture.

Avengers Chat AvengersChat is a demo application based on modern Android tech stacks and Stream Chat SDK. Previews Download Go to the Releases to down

Jaewoong Eum 352 Dec 25, 2022
AvengersChat is a demo application based on modern Android tech stacks and Stream Chat SDK.

?? Android sample Avengers chat application using Stream Chat SDK based on MVVM (ViewModel, Coroutines, Room, Hilt, Repository) architecture.

Stream 352 Dec 25, 2022
Telegram client based on official Android sources

Telegram messenger for Android Telegram is a messaging app with a focus on speed and security. It’s superfast, simple and free. This repo contains the

Dmitry Kotov 12 Dec 25, 2022
Conversations is an open source XMPP/Jabber client for Android

Conversations Conversations: the very last word in instant messaging Design principles Be as beautiful and easy to use as possible without sacrificing

Daniel Gultsch 4.2k Jan 9, 2023