【发布时间】:2016-06-05 21:11:32
【问题描述】:
我正在使用 MixPanel 发送推送通知,并在自定义有效负载上添加以下代码: {"sound":"default"} 问题是我收到通知时没有播放声音。有人对此有解决方案吗?
【问题讨论】:
标签: android push-notification mixpanel
我正在使用 MixPanel 发送推送通知,并在自定义有效负载上添加以下代码: {"sound":"default"} 问题是我收到通知时没有播放声音。有人对此有解决方案吗?
【问题讨论】:
标签: android push-notification mixpanel
也许这有助于找到here 代码看起来像这样。
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
【讨论】:
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();
从混合面板发送通知并查看它是否收到。这将在创建时使用用户设备上配置的默认声音发送通知。
【讨论】:
试试下面的代码
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);
【讨论】:
假设你有一个声明......
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));
【讨论】:
Android 的 Mixpanel 库中用于处理来自 Mixpanel 的传入推送通知的默认 GCMReceiver 不包含声音。您需要编写自己的 BroadcastReceiver 来处理来自 Mixpanel 的传入消息。
您可以查看 Mixpanel 使用低级 API 的文档:https://mixpanel.com/help/reference/android-push-notifications#advanced - 然后您可以应用其他答案中的建议来使用您的自定义数据负载做任何您想做的事情。
【讨论】: