【问题标题】:How to play a ringtone which is only for Push Notification Arrivals of my application?如何播放仅适用于我的应用程序的推送通知到达的铃声?
【发布时间】:2023-03-19 09:33:01
【问题描述】:

我正在使用 Android,我已经使用 GCM 在我的应用中实现了推送通知功能。

我的意图是仅当我的应用程序相关推送通知到达已安装的设备时,才从应用程序资产或设备 Sdcard 播放铃声。

【问题讨论】:

标签: android push-notification ringtone


【解决方案1】:

1.在yourApp/res/下创建1个名为raw的文件夹

2.复制并粘贴您的铃声到此文件夹

3.当您的应用程序通知通知时编写以下代码!

            SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

            int iTmp = sp.load(context, R.raw.windows_8_notify, 1); // in 2nd param u have to pass your desire ringtone

            sp.play(iTmp, 1, 1, 0, 0, 1);

            MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.windows_8_notify); // in 2nd param u have to pass your desire ringtone
            //mPlayer.prepare();
            mPlayer.start();

【讨论】:

  • 谢谢。它是否适用于推送通知。因为通知将由服务器端发送。
  • @Ganesh-是的,当你要从服务器发送时它会起作用..你试过了吗?
  • 我的意图是从 sdcard 播放音乐文件。当应用程序安装在设备中时,我想将音乐文件从服务器下载到 sdcard 或 ExternalCacheDirectory。
猜你喜欢
  • 1970-01-01
  • 2017-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多