0

I use the following code to send notification sound to user. This works perfect on the emulator, but not on a real device. Real device just remains silent.

NotificationManager notificationManager = (NotificationManager) reactContext.getSystemService(Context.NOTIFICATION_SERVICE);

Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getReactApplicationContext())
        .setContentTitle("foo")
    .setContentText("bar")
        .setSound(soundUri, AudioManager.STREAM_NOTIFICATION)
        .setAutoCancel(true);

notificationManager.notify(0, mBuilder.build());

Here are the app permissions I added:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="android.permission.BIND_CARRIER_SERVICES" />
<uses-permission android:name="android.permission.BIND_MIDI_DEVICE_SERVICE" />
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND" />
<uses-permission android:name="android.permission.REQUEST_COMPANION_USE_DATA_IN_BACKGROUND" />

Emulator target is Androd 6.0 on API v 23

What else could it be? Thanks

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Adam
  • 3,415
  • 4
  • 30
  • 49
  • 1
    Mention the API level of emulator and device in question . – ADM Apr 02 '18 at 07:05
  • Did you try when app is closed?? try it once you have to handle push notification manually when app is open – Praneeth Apr 02 '18 at 07:11
  • Application was open. Emulator target is Androd 6.0 on API v 23 – Adam Apr 02 '18 at 07:13
  • 1
    Sometime what happens is that, there are some battery optimization services are running on the real devices, which block the notifications. Go to your battery settings, and whitelist your app. – Insane Developer Apr 02 '18 at 07:47
  • That was it - the phone was in a battery save mode. That was blocking notifications. I'd never thought about that. Thanks. If you'd like to put it as answer, I will accept it – Adam Apr 02 '18 at 09:03

0 Answers0