Android通知不断重复通知声音

标签 android

以下是我的通知生成代码,但是声音一直在重复,直到拉下状态栏才能看到。

NotificationManager mNotificationManager;
        android.support.v7.app.NotificationCompat.Builder mBuilder;
        Notification mNotification;
        final int NOTIFICATION_ID = 1;

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

        PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, new Intent(ctx, HomeScreenTabbed.class), 0);

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        mBuilder = new android.support.v7.app.NotificationCompat.Builder(ctx);
        mBuilder.setContentTitle(notificationTitle);
        mBuilder.setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle().bigText(notificationBody));
        mBuilder.setContentText(notificationBody);
        mBuilder.setContentIntent(contentIntent);
        mBuilder.setSound(alarmSound);
        mBuilder.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher));
        mBuilder.setSmallIcon(R.drawable.ic_pollen_notification);
        mBuilder.setAutoCancel(true);
        mNotification = mBuilder.build();
        // set dismiss on click flags
        mNotification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_SOUND;
        mNotificationManager.notify(NOTIFICATION_ID, mNotification);

最佳答案

我通过使用 mNotification.defaults 代替 mNotification.flags 解决了这个问题

关于Android通知不断重复通知声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33315638/

相关文章:

java - 对 token 感到困惑

Android marshmallow edittext OnKeyListener 未在输入按钮上触发

android - 将 Unity3D 与 Vuforia 集成到 Cordova 应用程序中

android - JsonHttpParser.jsonFactory 字段不可见

java - 实现垂直搜索栏 - 如何在 Android Studio 中添加新类?

Android 电子邮件选择器

Android Lollipop 5.1 : Fatal signal 11 (SIGSEGV), 代码 2,错误地址 0x9e985ff8 in tid 4093 (RenderThread)/当使用大量 9-patch 图形时

android - 使用 Azure Windows 10 运行 Android 模拟器

java - 在 Android 应用程序上定位元素时出现 InvalidSelectorException

android - 将 mockito-core 更新到版本 3.0.0 后,Mockito 在 SharedPreferences 中返回 null