通知声音没有播放(wav文件)

时间:2013-12-18 16:18:10

标签: android notifications

我按如下方式设置了通知:

    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);

问题是它从不播放任何声音 我尝试使用相同的资源启动MediaPlayer对象并且它可以工作。

1 个答案:

答案 0 :(得分:1)

你的URI声音错误。 替换:

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

通过

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