Android 通知声音不播放,间歇性

标签 android android-notifications

我已经搜索过这个问题,如果这个问题已经得到解答,我深表歉意(我很高兴被重定向),但具体来说,我们的问题是间歇性的。

我们的客户提示当事件从我们的软件发送到他们的手机时,通知音频间歇性地没有“响起”。它会在一段时间内正常工作,然后“只停止几个小时”(根据我们客户的投诉推断)。

我们无法在内部重现此问题,但我们从客户那里得到的挫败感让我们确实需要修复它。

我们的客户坚称他们没有打电话、播放音频或运行其他软件,而且看到他们的手机后,我基本上相信了他们。

我们主要在 Jellybean 上注意到了这一点,因为这是我们大多数客户正在运行的,但它可能并非孤立于这种情况。

我是不是做错了什么,或者是否有更好的方法来“提示”通知。在这个阶段我很乐意尝试不同的东西

void updateNotification()
{
    Notification.Builder builder = new Notification.Builder(_context);

    // Set the appearance of the notification:
    int icon;
    String title;
    String description;

    // ...
    //CODE setting icon, title and description
    // ...

    builder.setSmallIcon(icon);
    builder.setContentTitle(title);
    builder.setContentText(description);
    builder.setTicker(description);

    // Set the sound for the notification:
    builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));

    Intent intent = new Intent(_context, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(MainActivity.EXTRA_TAB, MainActivity.EXTRA_TAB_TASKS);

    builder.setContentIntent(PendingIntent.getActivity(_context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Update the notification:
    NotificationManager manager = (NotificationManager)_context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(_notificationId, builder.build());
}

最佳答案

出于某种原因,我注意到某些设备在设置为静音或振动模式时会静音所有音量(包括闹钟音量)。在这些模式下,对于这些设备,除非您更改模式,否则无法更改此音量。

我有用户提示类似的问题,并且不得不通过强制更改模式来处理它以确保音量足够高。然后我播放音频并将模式切换回原始配置。

编辑:Here is a post来自对此提示的用户。请注意屏幕截图上的“警报”音量按钮在静音时被禁用。

编辑 2:在我的特定情况下,我运行以下检查以查看是否需要增加音量:

if (audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL
            && audioManager.getStreamVolume(AudioManager.STREAM_ALARM) == 0) {
    // Save current state and increase the volume
}

关于Android 通知声音不播放,间歇性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26225413/

相关文章:

android - 滚动后如何在 RecyclerView 中保存按钮状态?

android - 使用 ArcGis 在 OneMap 上显示位置

android-notifications - 带有 “null” PendingIntent的通知

android - 我无法通过通知栏进入应用程序

android - 收到通知后重新启动应用程序

android - 隐藏安卓工具栏

android - 为什么我在自定义 RecyclerView 中的项目图像在滚动时会发生变化?

android - 在模拟器上测试 Google map - CameraUpdateFactory 未初始化

java - 从服务中删除正在进行的通知

android - 分组通知计数 (+1),如 Gmail