设置通知音量而不设置铃声音量

时间:2014-09-27 19:30:27

标签: android notifications

我想管理所有系统通知的数量。

如果我使用此功能,则通话音量也会改变。

    audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);

如何只更改通知量?

由于

1 个答案:

答案 0 :(得分:0)

您可以使用通知类更改通知声音。即

NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(context.getResources().getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setContentIntent(contentIntent).setContentText(message);

Notification notification = mBuilder.build();
notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "/raw/generic");
mNotificationManager.notify(notificationId, notification);