我已经尝试了这里建议的许多方法,但都不适用于我。以下是我的源代码:
Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, resultIntent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("title")
.setContentText("Hello World!");
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
mBuilder.setContentIntent(contentIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
出现通知,但没有声音,有帮助吗?
发布于 2014-07-09 19:55:22
设置默认标志:
mBuilder.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE);
发布于 2016-08-06 02:00:43
检查一下我的声音设置就行了。通知级别一直降到了零。
这很棘手,因为除了通知之外,其他声音也可以工作。
发布于 2017-12-04 02:59:30
这也可能是因为与旧的API版本稍有不兼容。例如,当在SDK 25上编译但针对较旧版本(例如SDK 15)时,我添加了以下行来解决该问题:
notification.audioStreamType = AudioManager.STREAM_ALARM;
https://stackoverflow.com/questions/17459410
复制相似问题