Android 自定义通知声音不播放

Android 自定义通知声音不播放,android,android-notifications,android-notification-bar,Android,Android Notifications,Android Notification Bar,我正在尝试在状态栏通知上进行自定义声音播放。.mp3文件的格式为res/raw/。但当我通知用户时,声音不会播放。我试过使用MediaPlayer,它很有效,但我不想让它与MediaPlayer一起使用 以下是我的方法: public void showNotification() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (Noti

我正在尝试在状态栏通知上进行自定义声音播放。.mp3文件的格式为res/raw/。但当我通知用户时,声音不会播放。我试过使用MediaPlayer,它很有效,但我不想让它与MediaPlayer一起使用

以下是我的方法:

public void showNotification()
{
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

        int icon = R.drawable.feedback;        // icon from resources
        CharSequence tickerText = mContext.getString(R.string.statusbar_notification); // ticker-text
        long when = System.currentTimeMillis();         // notification time
        Context context = getApplicationContext();      // application Context
        CharSequence contentTitle = mContext.getString(R.string.statusbar_notification);  // message title
        CharSequence contentText = mContext.getString(R.string.statusbar_notificatione_detailed);      // message text

        Intent notificationIntent = new Intent(mContext, Main.class);
        PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);

        // the next two lines initialize the Notification, using the configurations above
        Notification notification = new Notification(icon, tickerText, when);

        //notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.sound = Uri.parse("android.resource://" + getPackageName() + "/R.raw.notificationsound");

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        mNotificationManager.notify(1, notification);
}

谢谢。

来自ContentResolver的文档:

Uri应为以下格式之一: 安卓resource://package_name/id_number

您正在传递字符串“R.raw.notificationsound”,它没有任何意义。 相反,请尝试以下方法:

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

如何设置这些通知声音的持续时间周期…如何在这些声音上重复模式