Bluemix Android Push Notification unable to implement custom sound notification

依然范特西╮ 提交于 2019-12-10 21:28:01

问题


I'm trying to implement Bluemix Push Notification custom sound in Android with Mobile First Services Starter (MFSS) and/or Mobile App Builder. At the moment I can send simple push notifications to devices and works well.

The problem comes when I want to play a sound for notification.

With MFSS I'm trying using this code:

 MFPPushNotificationListener notificationListener = new MFPPushNotificationListener() {
    @Override
    public void onReceive(final MFPSimplePushNotification message) 


        Log.e("message arrives", message.toString());
        NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


        Notification noty = new Notification.Builder(getApplicationContext())
                .setTicker("Entrando al area de ROPA")
                .setSmallIcon(R.drawable.ic_cast_dark)
                .setWhen(System.currentTimeMillis())
                .setContentText("Hello World")
                .setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification))
                .setContentInfo("Set ContextInfo")
                .setContentTitle("Set title")
                .setContentInfo(message.getAlert().toString())
                .build();

        PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);

        notif.notify(0, noty);
    }
};

On the other side also I'm trying using the IMF Push Service REST API with this payload the messages arrives but doesn't play the sound::

{
    "message": {
    "alert": "mensaje"
},

"settings": {
    "gcm": {
        "payload": {
            "sound": "notification.wav"
        }
    }
}

}

Finally from the push notification dashboard I'm using the documentation payload, also the messages arrives but doesn't play the sound:

 "settings":{
     "gcm":{
     "sound":"notification.wav",
  }
 }

Note: I'm created the raw folder in order to save the notification.wav file, also I'm implementing a button click listener in order to test the sound file and works well, the sound it's clear.

Any help will be appreciated.


回答1:


I just tested Push notifications with sound on the latest version of the Android Push SDK, and got it working with my Android phone.

Here is initializing my application:

Here is my sound file:

Here was my request:




回答2:


As of a few hours ago, version 2.0.1 of the Bluemix android push sdk was published to support notification sound.

Keep in mind, you will need to save your sound file in the res/raw directory and then you will be able use the documented payload like you mention:

"settings":{
     "gcm":{
     "sound":"notification.wav",
  }
 }

Apologies for the delay/confusion.



来源:https://stackoverflow.com/questions/37364262/bluemix-android-push-notification-unable-to-implement-custom-sound-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!