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

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

tech