2

I am working on an emergency messaging app in android. The most important part of this app is showing notifications for a new message when the app is in background and the user is not interacting with the app. The notification requirement is that the phone should vibrate and play a notification sound when posting a notification to the notification bar.

I have most of the notification part working and the notifications work fine for most of the scenarios. The problem that I am facing is that whenever the user is on a call and receives a notification, the phone doesn't vibrate or play a notification sound but the notification does appear in the notification bar.

So if the user gets a notification while on a call he cannot know about the notification until he gets off the call. As the whole purpose of the app is emergency messaging I cannot afford this and want the app to vibrate and play sound as soon as a notification comes in.

The code that I am using for generating the notification is as shown below

                int requestID = (int) System.currentTimeMillis();
                PendingIntent pendingIntent = PendingIntent.getActivity(context, requestID,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                Notification notification = new NotificationCompat
                    .Builder(context)
                    .setContentTitle("Title")
                    .setContentText("Text")
                    .setSmallIcon(R.drawable.app_icon)
                    .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
                    .setWhen(Calendar.getInstance().getTimeInMillis())
                    .setContentIntent(pendingIntent)
                    .setAutoCancel(true)  //cancel the notification on click
                    .build();
                notificationManager.notify(notificationId++, notification); 

This code works fine when the user is not on the call and the phone vibrates and plays the notification sound for an incoming notification. But it fails to do so when that user is on an ongoing call.

My question is that, is it possible for a third party app to create notifications such that they would vibrate and play notification sound even when the user is on a call? If yes, then what is the right way to do that and if not then what is the best work around?

I am targeting android api level 16 and above.

Thank you in advance.

2
  • I would doubt this is possible in stock Android. Imagine how annoying it would be to hear notification sounds while you're trying to listen to someone during a call. Vibrate might be possible, but again, I suspect any reasonable implementation would disable all non-visual notifications while the user is concentrated on the call.
    – adelphus
    Sep 30, 2015 at 0:18
  • Thank you for you reply @adelphus. You said vibrate might be possible. Can you give an example on how I might do that or point me to something that might help me implement that.
    – rbing
    Sep 30, 2015 at 1:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.