0
我使用Notifiation构建器并希望声音,振动和光线。 振动和光线工作正常,但声音不想玩。我在这里尝试了很多解决方案,但大部分都是针对不推荐使用的版本。 在下面的代码中你可以看到我在做什么。我尝试了alamsound和声音,但都没有奏效。 我需要任何权限吗?Android通知生成器声音
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());
}