android - 打开通知面板时通知声音停止

标签 android android-notifications

我正在处理一个项目,我在通知中遇到了一个奇怪的问题。
基本上我想在通知中播放警报,为此我在通知生成器中添加声音,即uri。
这是我的代码:

builder.setSmallIcon(R.mipmap.app_icon).setContentTitle(title)
            .setContentText(msg)
            .setColor(getResources().getColor(R.color.white))
            .addAction(R.drawable.alarm_off, getString(R.string.dismiss), pendingIntent)
            .setOngoing(true)
            .setSound(Uri.parse(path));

    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_INSISTENT;


    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(WAKE_UP_ALARM_ID, notification);

通知出现在面板中,但是当我触摸通知面板向下滚动时,音乐会自动停止。
我无法理解这种情况。

请帮我解决问题。

谢谢

最佳答案

The flags that are used in notification builder

1.Notification.DEFAULT_SOUND:used to play sound.

2.Notification.FLAG_INSISTENT:this flag is makes your sound to ring continuously until you have done few operations on notification ie, either you drag the bar or you click the bar.

3.Notification.FLAG_AUTO_CANCEL:this flag is used to automatically cancel the notification after you have seen it

关于android - 打开通知面板时通知声音停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31160952/

相关文章:

android - 在android中将文本包裹在贝塞尔曲线之外

Android - getHeight() 和 getWidth()

android - 当应用程序被销毁时,通知栏中的异步任务和下载进度不起作用

android - NotificationManager.notify 创建*最初*缺少 contentText 的通知

android - PhoneGap Build - 无法为 org.gradle 类型的对象获取未知属性 'GMS_VERSION'

android - 使用 add() 方法添加 fragment 不会隐藏以前的 fragment

java - 在 Android Studio Java 代码中接受自签名证书

android - 通过单击按钮创建 android 通知

android - 如何获取信息注册。状态栏中的通知处于 Activity 状态

android - 是否可以在 Android 通知中使用自定义(不可绘制)smallIcon?