2013-12-18 43 views
0

我設置的通知如下:通知聲音沒有播放(wav文件)

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

您在聲音的URI中犯了錯誤。 替換:

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

通過

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

感謝我必須等待一兩分鐘,但我會盡快標誌着這是公認的答案。 – Ayoub