Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 878
Ganesh Avatar asked Apr 03 '13 06:04

Ganesh


People also ask

How do phones receive push notifications?

Client app– The app which receives the push notification. App server– To understand how to send push notification to the users who have installed your app, you have to create an app server. This server sends the message to the GCM (discussed later) which then transmits it to the client app.

Can Android emulator receive push notifications?

The emulator must enable the Google API for Google Play services. To resolve this issue, the mobile developer must create an emulator that uses Google API as the target OS.

What is a push app notification?

What are push notifications? A push notification is a message that pops up on a mobile device, such as a sports score, an invitation to a flash sale or a coupon for downloading. App publishers can send them at any time, since users don't have to be in the app or using their devices to receive them.


1 Answers

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();
like image 172
TheFlash Avatar answered Nov 15 '22 00:11

TheFlash