Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android通知不断重复通知声音_Android - Fatal编程技术网

Android通知不断重复通知声音

Android通知不断重复通知声音,android,Android,下面是我的通知生成代码,但声音不断重复,直到拉下状态栏进行检查。有什么想法吗 NotificationManager mNotificationManager; android.support.v7.app.NotificationCompat.Builder mBuilder; Notification mNotification; final int NOTIFICATION_ID = 1; mNotificationMana

下面是我的通知生成代码,但声音不断重复,直到拉下状态栏进行检查。有什么想法吗

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.flags定义中添加一次标志flag\u ONLY\u ALERT\u


这将防止它多次发送声音。

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


愉快编码

此选项的可能重复会使所有后续通知的声音静音。此外,我必须删除所有其他标志,以便使标志仅在生效时发出警报。您刚刚阻止了我的应用被删除。