How do I play a ringtone that is only for the Push Notification Arrivals of my application?

I am working on Android and I applied the Push Notifications feature in my application using GCM.

And I'm going to play a ringtone from the Assets application or the Sdcard of the device, when only for my application related to the notification message on the installed device.

+5
source share
1 answer

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

2. Copy and paste your ringtone into this folder

3. Write down the code below when your application notifies you.!

            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();
+1
source

All Articles