0

I was working with notifications and trying to understand how it works. There are different classes to handle notifications for old APIs like NotificationCompat and Notification(for new APIs). I followed the method invocation of NotificationCompat.build().

The pattern how it worked:

NotificationCompat.Builder.build() ->   
NotificaitonCompatIMPL.build() ->  
NotificationCompatImplJellyBean.build() ->  
NotificationCompatJellybean.Builder() ->   
Notification.Builder()

Note that not all of the above methods/constructors are static. They have been written with reference to class name so as to identify the class to which the method belongs.

And then I realized that the old methods are actually calling the new ones. So my question is what is the point of having compat classes if they are calling new methods in their internal implementation.

I know how to make a notification but I need to get some methods inside those classes by overriding methods or using Java reflection so that I can know to which type of class is resId of setSmallIcon converted. Is it drawable or Icon? because I don't have a resID for the drawable, it is made dynamically.

vishal-wadhwa
  • 1,021
  • 12
  • 18
  • Possible duplicate of [How to create a notification with NotificationCompat.Builder?](http://stackoverflow.com/questions/13902115/how-to-create-a-notification-with-notificationcompat-builder) – Umar Ata Dec 08 '16 at 06:37
  • @UmarAta I know how to make a notification but I need to get some methods inside those classes by overriding methods or using Java reflection so that I can know to which type of class is resId of setSmallIcon converted. Is it drawable or Icon? – vishal-wadhwa Dec 08 '16 at 07:15
  • You need to use a drawable by using code getResources().getDrawable(R.drawable.yourdrablename) – Umar Ata Dec 08 '16 at 17:42
  • No. I don't have the drawable in res. I am generating it programatically. – vishal-wadhwa Dec 08 '16 at 17:47
  • Then you can try new BitmapDrawable(getResources(), bitmap); – Umar Ata Dec 08 '16 at 17:51
  • By the way you must have a drawble in res because onReceived method get called only when your app in background or foreground if it is killed then android os will show in system tray with default icon you presented in manifest – Umar Ata Dec 08 '16 at 17:55
  • That is the problem I can't have a drawable in res because I am drawing text over it which is not possible in xml drawables. – vishal-wadhwa Dec 09 '16 at 06:02

0 Answers0