Android:通知不会生成默认声音

时间:2018-05-14 06:34:36

标签: java android firebase firebase-cloud-messaging android-notifications

我正在尝试使用声音生成FCM通知。我收到通知等没有问题,但根本没有声音。我可以使用默认的通知声音。请检查以下代码。它适用于API 26及更高版本。

SELECT en.employee,  
    en.entry_date,
    ex.exit_date,
    en.entry_time,
    ex.exit_time,
TIMEDIFF(ex.exit_time, en.entry_time) as duration
FROM (
    SELECT employee,
        ac_date AS entry_date,
        ac_time AS entry_time,
        @enRank := @enRank + 1 AS rank
    FROM AC, (SELECT @enRank := 0) r
    WHERE ac_event = 1 ORDER BY employee, ac_date, ac_time) en
LEFT JOIN (
            SELECT employee,
                ac_date AS exit_date,
                ac_time AS exit_time,
                @exRank := @exRank + 1 AS rank
            FROM AC, (SELECT @exRank := 0) r
            WHERE ac_event = 0 ORDER BY employee, ac_date, ac_time) ex ON ex.rank = en.rank
AND ex.employee = en.employee
WHERE en.entry_date >= '2018-05-12' AND ex.exit_date <= '2018-05-13'
ORDER BY en.entry_date

为什么会发生这种情况以及如何获取默认声音?

2 个答案:

答案 0 :(得分:0)

更改此部分:

// Create a notification and set the notification channel.
                Notification notification = new Notification.Builder(this,"xxx")
                        .setSmallIcon(R.drawable.volusha_notifications)
                        .setContentText(text)
                        .setChannelId(CHANNEL_ID)
                        .setContentIntent(pendingIntent)
                        .setContentTitle(title)
                        .setAutoCancel(true)
                        .build();

// Create a notification and set the notification channel.
                Notification notification = new Notification.Builder(this,"xxx")
                        .setSmallIcon(R.drawable.volusha_notifications)
                        .setContentText(text)
                        .setChannelId(CHANNEL_ID)
                        .setContentIntent(pendingIntent)
                        .setContentTitle(title)
                        .setSound(RingtoneManager
                              .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setAutoCancel(true)
                        .build();

答案 1 :(得分:0)

尝试使用RingtoneManager将默认通知Uri设为:

Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
builder.setSound(uri);