How to play a ringtone which is only for Push Notification Arrivals of my application?
Asked Answered
J

1

6

I am working on Android, and I have implemented Push Notifications feature in my app using GCM.

And my intention is to play a ringtone from app Assets or device Sdcard when only for my Application related push Notification arrivals in the installed device.

Joli answered 3/4, 2013 at 6:40 Comment(1)
take a look at this:: Setting Ringtone notification from SD card fileGlimpse
B
1

1.Create 1 folder named raw under yourApp/res/

2.Do copy and paste your ringtone in this folder

3.Write the below code when your application notify the notification.!

            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();
Brenan answered 3/4, 2013 at 6:55 Comment(4)
Thank you.And Does it works with push notifications. because notifications are going to sends by the server side .Joli
@Ganesh-Yes it will work when you are going to send from server..Have you tried it?Brenan
My Intentions is to play music file from sdcard. and I would like to download the music file from server to sdcard or ExternalCacheDirectory when application installs in device .Joli
@Ganesh-Check this #12006066 also easyandroidtutorials.blogspot.in/2012/09/…Brenan

© 2022 - 2024 — McMap. All rights reserved.