2

I am trying to build a call application using webrtc and socket.io. I am using firebase messaging to wake up the user. I am trying to find a way to notify user with playing a ringtone like when you get call on whatsapp they play default incoming call ringtone. I tried solutions like -

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();  

another is -

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
MediaPlayer mp = MediaPlayer.create(getApplicationContext(), notification);
mp.start();

but it does not respect user's sound setting i.e sound plays even when phone is put on vibrate or dnd.

Shahid Kamal
  • 380
  • 2
  • 14

1 Answers1

1

At least google in native phone app explicitly checks phone state, you can take a look here https://android.googlesource.com/platform/packages/apps/Phone/+/eclair-sholes-release/src/com/android/phone

and here is the logic, enjoy spaghetti from ring() method =) https://android.googlesource.com/platform/packages/apps/Phone/+/eclair-sholes-release/src/com/android/phone/Ringer.java#124

c0dehunter
  • 6,412
  • 16
  • 77
  • 139
Link182
  • 733
  • 6
  • 15