Ayoub
Ayoub

Reputation: 341

Notification sound not playing (wav file)

I set a notification as follows:

    Intent getBackIntent = new Intent (_context, Timers.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(_context);
    stackBuilder.addParentStack(Timers.class);
    stackBuilder.addNextIntent(getBackIntent);

    PendingIntent getBackPendingIntent = stackBuilder.getPendingIntent(C.NOTIFICATION, PendingIntent.FLAG_UPDATE_CURRENT);

    Uri soundUri = Uri.parse("android.resuource://" + getPackageName() + "/" + R.raw.notification);

    long[] pattern = {50,50,50};

    _notificationBuilder = new NotificationCompat.Builder(_context);
    _notificationBuilder.setSmallIcon(R.drawable.icon);
    _notificationBuilder.setContentTitle("Timeneye");
    _notificationBuilder.setContentIntent(getBackPendingIntent);
    _notificationBuilder.setStyle(new NotificationCompat.InboxStyle());
    _notificationBuilder.setSound(soundUri);
    _notificationBuilder.setVibrate(pattern);
    _notificationBuilder.setLights(Color.RED, 500, 500);
    _notificationBuilder.setAutoCancel(true);

    _notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

the problem is that it never plays any sound.
I tryed to start a MediaPlayer object with the same resource and it works.

Upvotes: 0

Views: 1529

Answers (1)

Andros
Andros

Reputation: 4069

You made a mistake in your URI for your sound. Replace :

Uri soundUri = Uri.parse("android.resuource://" + getPackageName() + "/" + R.raw.notification);

by

Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification);

Upvotes: 1

Related Questions