我正在使用MixPanel发送推送通知,并在自定义有效载荷上添加了以下代码: {“sound”:“default”}问题当没有声音播放时我收到通知。有没有人有这个解决方案?Android推送通知如何播放默认声音
回答
也许这有助于发现here代码看起来像这样。
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
假设你有一个声明......
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setTicker(title)
.setWhen(ts)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setContentText(message);
...变量在你的代码的某个地方建造,试试这个:
final String ringTone = "default ringtone"; // or store in preferences, and fallback to this
mBuilder.setSound(Uri.parse(ringTone));
我得到一个错误,说“mBuilder未初始化”如果我点击修复按钮Eclipse自动初始化mBuilder为空,当我运行应用程序崩溃 – Signo 2014-09-03 07:31:55
我提到“假设”你有它填充的地方。无论如何,它看起来像上面编辑的代码。请注意,您必须设置标题,ts和消息变量! – alpinescrambler 2014-09-03 07:34:11
对我来说是正确的答案(使用改编的Xamarin代码)。完全忘了检查Builder是否有SetSound方法!谢谢。 – nrod 2015-05-22 15:37:16
试试下面的代码
Notification notification = new Notification(R.drawable.appicon,
"Notification", System.currentTimeMillis());
notification.defaults = Notification.DEFAULT_SOUND;
final Notification notification =
new Notification(iconResId, tickerText, System.currentTimeMillis());
final String packageName = context.getPackageName();
notification.sound =
Uri.parse("android.resource://" + packageName + "/" + soundResId);
处理来自Mixpanel的传入推送通知的Android的Mixpanel库中的默认GCMReceiver不包含声音。您需要编写自己的BroadcastReceiver来处理来自Mixpanel的传入消息。
您可以看看Mixpanel的文档,以了解如何使用低级API:https://mixpanel.com/help/reference/android-push-notifications#advanced - 然后您可以应用其他答案中的建议来根据您的自定义数据有效载荷执行任何操作。
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
为了使用mixpanel发送通知+音效,你需要做到以下几点:
下面的代码添加到的onCreate:从
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI); Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification); r.play();
发送通知并看到它收到。这将通过用户设备上配置的默认声音发送创建通知。
- 1. 仅限播放通知默认声音(Android)
- 2. Android通知播放默认声音,而不是自定义
- 3. iPhone推送通知 - 如何使用默认声音
- 4. 如何使用Apple推送通知播放自定义声音?
- 5. Android通知声音默认返回而不是播放自定义声音
- 6. 如何使Bluemix推送通知在Android上播放声音和振动
- 7. Worklight 6.1中的默认推送通知声音
- 8. Android Mixpanel推送通知声音
- 9. 声音推送通知
- 10. 在播放时取消推送通知声音
- 11. iOS 10.0.1推送通知自定义声音不播放(MP3)
- 12. 自定义声音不能播放推送通知
- 13. android无法从通知播放声音
- 14. 如何更改推送通知声音?
- 15. 如何使用Javascript为Android Android版Chrome播放声音通知?
- 16. 当我收到Parse的推送通知时,如何播放声音?
- 17. 如何在Apple推送通知服务中播放Cutom声音文件?
- 18. iPhone推送通知的声音,“声音通知”
- 19. 播放默认声音后定时器
- 20. Android静默推送通知
- 21. android:默认声音
- 22. 推送通知声音不起作用
- 23. iOS推送通知自定义声音
- 24. IOS推送通知声音不工作
- 25. 推送通知的另一个声音
- 26. 推送通知:声音和徽章
- 27. 推送通知 - 声音不工作?
- 28. 反应本机推送通知声音
- 29. 苹果推送通知声音
- 30. 推送通知的自定义声音
是否可以在清单中设置推送通知声音? – Pruthviraj 2016-04-29 11:03:51