Bluemix Android推送通知无法实现自定义声音通知。

3
我正在尝试在使用Mobile First Services Starter (MFSS)和/或Mobile App Builder的Android应用中实现Bluemix推送通知自定义声音。目前,我可以向设备发送简单的推送通知,并且运作良好。
问题出现在当我想要播放通知声音时。
通过使用MFSS,我正在尝试使用以下代码:
 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);
    }
};

另外,我也尝试使用IMF推送服务REST API,使用此有效负载消息可以到达,但无法播放声音:
{
    "message": {
    "alert": "mensaje"
},

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

最终,我正在使用推送通知仪表板的文档有效负载,消息也到达了,但没有播放声音:
 "settings":{
     "gcm":{
     "sound":"notification.wav",
  }
 }

注意:我已经创建了原始文件夹以保存notification.wav文件,同时我正在实现一个按钮点击监听器来测试声音文件是否正常工作,声音很清晰。
任何帮助将不胜感激。

1
我们也遇到了这个问题,并已将其带给开发人员的注意。更多更新即将到来。 - Dave Cariello
2个回答

2
我刚在最新版本的Android Push SDK上测试了带有声音的推送通知,并且已经让它在我的Android手机上工作了。
这是我的应用程序初始化: 这是我的声音文件:enter image description here 这是我的请求:enter image description here

感谢您的回复,我看到推送通知的新版本2.0.1现在可以使用推送消息仪表板正常工作。然而,我的应用程序使用NODE-RED,灵感来自于这个教程:https://www.ibm.com/developerworks/library/wa-nodered-push-app/为了发送具有自定义有效负载的推送通知,我注意到,由于某种原因,推送消息并不总是到达设备,我还尝试使用IMF Push Service REST API,但结果相同。https://mobile.ng.bluemix.net/imfpushrestapidocs/#!/messages/post_apps_applicationId_messages问候, - user3368141
你是在使用模拟器还是真实设备? - joe
我正在使用一台真实设备(华为Ascend)。 - user3368141
1
你能否创建一个新问题来描述你的新问题?这样其他人遇到相同的问题时就可以找到解决方法了。 - joe

0

几个小时前,Bluemix Android推送SDK的2.0.1版本已经发布,支持通知声音。

请注意,您需要将声音文件保存在res/raw目录中,然后您将能够使用像您提到的文档有效载荷:

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

对于延迟/混淆表示歉意。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接