android-notifications
Bad notification posted from package Couldn’t expand RemoteViews
I noticed this happening on 3.0 emulators, when I set the Large Icon. So, since the Large Icon is only used by 4.0+ devices, I solved this issue by checking if the Build version is > 13. If so (and only if so), I set the Large icon. The problem has gone.
Android O – Single line Notification – like the “Android System – USB charging this device”
To display a compact single line notification like the charging notification, you have to create a Notification Channel with priority to IMPORTANCE_MIN. @TargetApi(Build.VERSION_CODES.O) private static void createFgServiceChannel(Context context) { NotificationChannel channel = new NotificationChannel(“channel_id”, “Channel Name”, NotificationManager.IMPORTANCE_MIN); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.createNotificationChannel(channel); } And then create an ongoing notification like that: public static Notification … Read more
Can I test status bar notifications using Android’s testing framework?
Maybe not the answer you are looking for, but as usual, the solution is to: Create an interface abstracting the notification functionality. Create a default implementation that delegates to the system notification API. When running tests replace (or decorate) the default implementation with a mock implementation that supports testing. This can be simplified with the … Read more
How to Dismiss/Cancel the status bar notification in android programmatically
You can use this : public void clearNotification() { NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); }
Android: Grouped notifications and summary still shown separately on 4.4 and below
Fixed this by using NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); instead of NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); and replacing NotificationManager with NotificationManagerCompat in corresponding method signatures.
Listen to incoming Whatsapp messages/notifications
I was able to do this using Accessibility Service . Using this, you can listen to all notification on the notification bar. I listened to application-specification by adding the package name to the Accessibility Service service info , which in this case was com.whatsapp. I couldn’t read the messages, but I get notified whenever a … Read more
Adding button action in custom notification
Start notification as: private void startNotification(){ String ns = Context.NOTIFICATION_SERVICE; NotificationManager notificationManager = (NotificationManager) getSystemService(ns); Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis()); RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.mynotification); //the intent that is started when the notification is clicked (works) Intent notificationIntent = new Intent(this, FlashLight.class); PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.contentView = notificationView; … Read more