Awar Pulldozer
Awar Pulldozer

Reputation: 1101

android push notification sound

i have small android project and this is my notifications code

public class MyfirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Intent intent = new Intent(this,MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    notificationBuilder.setContentTitle("FCM NOTIFICATION");
    notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
    notificationBuilder.setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0,notificationBuilder.build());
 }
}

but when the notification come there is no sound any help please thanks

Upvotes: 0

Views: 337

Answers (1)

Mortuza Shahariar
Mortuza Shahariar

Reputation: 94

Add this code

Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notifysound);
notificationBuilder.setSound(sound);

and put notifysound into raw folder.

Upvotes: 1

Related Questions