【问题标题】:Play multiple different notification sounds from app从应用程序播放多种不同的通知声音
【发布时间】:2014-06-30 09:15:47
【问题描述】:

iOS 或 android 应用程序是否可以启动系统通知。通知播放的声音是否会根据某些条件发生变化?

如果可以,两个平台都可以吗?

【问题讨论】:

  • 在 iOS 中是可能的。您必须在创建通知时设置声音文件名。如果是推送通知,则只需在推送有效负载中提及声音名称。只有一个限制是声音文件不应超过 30 秒。

标签: android ios cordova push-notification


【解决方案1】:

两个平台都可以这样做。

在 iOS 中,如评论中所述,您可以发送带有声音文件名的 push notification payload。 例如,如果此文件与您的应用程序捆绑在一起,则以下有效负载将显示警报并播放声音文件名。

{"aps":{"alert":"my message","sound":"sound-file-name"}}

在 Android 中,当您构建通知时,您可以使用 setSound(uri) 为通知设置声音。

public NotificationCompat.Builder setSound(Uri 声音)

设置要播放的声音。它将在默认流上播放。

或者您可以使用setDefaults(Notification.DEFAULT_SOUND) 播放默认声音。

例如:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
  .setDefaults(Notification.DEFAULT_SOUND)
  .setTicker (text)
  .setSmallIcon(R.drawable.icon)
  .setContentText (text)
  .setContentTitle(title)
  .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
  .setAutoCancel(true).setNumber (4)
  .setContentIntent(contentIntent);

mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

【讨论】:

  • 酷!现在我只需要找到一个可以做到这一点的cordova插件或将此功能添加到通知cordova插件中。
猜你喜欢
  • 1970-01-01
  • 2015-11-01
  • 1970-01-01
  • 2013-01-18
  • 1970-01-01
  • 2021-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多