[英]Android notification keeps on repeating notification sound
以下是我的通知生成代碼,但聲音不斷重復,直到拉下狀態欄進行檢查。 任何的想法?
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
解決了這個問題
嘗試將標志 FLAG_ONLY_ALERT_ONCE 添加到您的 mNotification.flags 定義中。
http://developer.android.com/reference/android/app/Notification.html#FLAG_ONLY_ALERT_ONCE
這應該可以防止它多次發送聲音。
只是這個
.setOnlyAlertOnce(真)
快樂編碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.