Sunday, 29 January 2017

Why do my Android Notification only appear in the status bar?

I'm definitely getting back into Android development, I'm remembering that feeling of 'Surely this should be easier than this!'. All I wanted to do was to schedule a local notification which behaved similar to a push notification pop-up. That is, as well as showing the small icon in the status bar I wanted it to pop up on screen to notify the end user. All seems fairly easily, I found this code for how to schedule a notification. That all worked perfectly, apart from the notification would only appear in the status bar. Searching around I found loads of different answers / solutions, mostly all saying the same thing:

  • It only worked if you used 'NotificationCompat.Builder' in place of 'Notification.Builder', or
  • You had to set the priority to 'NotificationCompat.PRIORITY_HIGH'

As usually happens, none of these solutions worked for me until I added in the missing piece of the jigsaw:- '.setDefaults(Notification.DEFAULT_ALL)'. For me this fixed the problem, the scheduled notification began to pop up on the desktop as expected! Looking into the Android documentation for this method nothing seemed to make sense as to why it would change the behaviour of the notification. As the documentation made reference to default sounds I replaced the call ".setDefaults(...)" with ".setSound(...)" and tried again. Again, the notification behaved as desired and appeared as a pop-up. Not making calls to either of these methods resulted in the notification reverted back the undesired behaviour of only appearing in the status bar. Adding either or both of these calls back in caused the desired behaviour. I'm still not completely sure why at the moment, but adding a sound to the scheduled notification sorted the problem out for me.

These 'pop-up' notifications are called “Heads-up” notifications and were introduced with Lollipop (v5.0).

Saturday, 14 January 2017

Links for starting out in Android development

A recent discussion at work made me realise that over the past few years learning Android development I've managed to build a short but very useful list of links for starting out. Not a really detailed post this time around, but hopefully these links help at least one person, let me know!

  • Development environment: We started out using Eclipse, but now feel that there is only one IDE to learn, Android Studio 2.x
  • How to documentation: This has always been a big struggle, much of the information that you can find is quickly out of date and potentially incorrect. Luckily a team of volunteers have set up the Codepath Android Cliff-notes as a Github wiki. This team have also recognised the difficulty faced by many starting out with Android development and have put together a list of articles tackling everything to do with Android development and are maintaining that list to ensure it is regularly reviewed / updated to keep it relevant and useful. I really wish I'd found this when I first started out.
  • Training videos: At my company we all have Pluralsight subscriptions (well recommended). I can recommend the course by Sriyank Siddhartha. Again, everything ages with Android really badly so these articles were useful around 2016/7.
  • More detailed videos: The Android development team at Google put together a great YouTube channel. These videos are usually really in depth but require a little more than entry level knowledge to get the most from. Either good to watch to get a feel for what's available or coming back to when you need to tackle a particular problem.

That's all, enjoy learning Android!