質問

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.

役に立ちましたか?

解決

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();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top