0

我正在使用通知生成器并且想要声音、振动和光。振动和灯光工作正常,但声音不想播放。我在这里尝试了很多解决方案,但大多数都是针对已弃用的版本。在下面的代码中你可以看到我在做什么。我尝试了 alamsound 和 sound 但都没有奏效。我需要任何许可吗?

    public void createTestNotification(){
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    long[] vibrate = { 0, 100, 200, 300 };
    NotificationManager nm= (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    Uri sound = Uri.parse("android.resource://com.uks.uksnavigation/" + R.raw.notification);


    Intent intent = new Intent(this.getActivity(), MainActivity.class);
    intent.setAction("nachricht");
    PendingIntent pIntent = PendingIntent.getActivity(getActivity(), 0, intent, 0);

    Notification.Builder mBuilder =
            new Notification.Builder(getActivity())
    .setContentIntent(pIntent)
            .setSmallIcon(R.drawable.ic_stat_mail_aktiv)
            .setContentTitle("New Message")
            .setContentText("Nachrichten text text text")
            .setSound(sound)
            .setVibrate(vibrate)
            .setLights(Color.BLUE, 500, 500);

    nm.notify(1, mBuilder.build());     


}
4

1 回答 1

1

使用Uri.parse("android.resource://com.uks.uksnavigation/raw/notification").

于 2013-10-18T04:09:22.523 回答