Android Notification Not getting Sound And Vibration

前端 未结 4 740
执念已碎
执念已碎 2020-12-11 20:11

I\'ve used FCM Notifications in My app , I\'m Receiving Them and it\'s showing Title And message Perfectly

But,When i\'m receiving the Notification Im not getting an

相关标签:
4条回答
  • 2020-12-11 20:21

    Android Notification Not getting Sound And Vibration

    Try to use default RingtoneManager

    Remove builder.setSound(Uri.parse("file:///android_asset/notification.mp3"));

    Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    builder.setSound(uri);
    

    Added permissions in android manifest for vibrate.

    <uses-permission android:name="android.permission.VIBRATE" />
    

    Important Note: Make sure Android Push Notification Service correctly configure by cloud server-side(GCM/Firebase)

    Confirm that you are getting correct payload for downstream (JSON)

     {
          "to": "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
          "notification": {
            "body": "great match!",
            "title": "SamDev Test",
            "icon": "myicon",
            "sound": "default"
          }
        }
    
    0 讨论(0)
  • 2020-12-11 20:25

    IMO you have to add permissions in manifest file like below

    <uses-permission android:name="android.permission.VIBRATE" />
    
    0 讨论(0)
  • 2020-12-11 20:31

    1. When you send push notification from firebase make sure that sound option enabled

    like this

    2. Also make sure that you have added permissions in android manifest for vibrate.

    <uses-permission android:name="android.permission.VIBRATE" />
    

    3. If you are sending from server than use payload

    notification payload of the notification there is a sound key.

    From the official documentation its use is:

    Indicates a sound to play when the device receives a notification. Supports default or the filename of a sound resource bundled in the app. Sound files must reside in /res/raw/.

    {
        "to" : ".......",
    
        "notification" : {
          "body" : "body",
          "title" : "title",
          "icon" : "myicon",
          "sound" : "default"
        }
      }
    
    0 讨论(0)
  • 2020-12-11 20:36

    Try this

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    builder.setSound(alarmSound);
    
    0 讨论(0)
提交回复
热议问题