如何使游戏的自定义通知声音只有一次 [英] How to make play custom notification sound only once

查看:221
本文介绍了如何使游戏的自定义通知声音只有一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建自定义声音,振动以及一些短信通知。但是,我不能化妆通知播放自定义的声音只有一次。
在我的情况不断播放,直至用户拉动抽屉
这里是我的code,

I have created notification with custom sound ,vibration and some text message. But, I'm unable make notification to play custom sound only once. In my case it keeps on playing until user pulls the drawer Here is my code,

 public synchronized static void createNotification(Context context,
            String message, int soundFile, int notifyId) {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context);
        Intent notificationIntent = new Intent(context, DashBoardActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent contentIntent;
        contentIntent = PendingIntent.getActivity(context, 0,
                notificationIntent, 0);
        mBuilder.setSmallIcon(R.drawable.notification)
                .setContentIntent(contentIntent)
                .setContentTitle(
                        context.getResources().getString(
                                R.string.schoolezone_map_title))
                .setContentText(message)
                .setAutoCancel(true)
                .setStyle(
                        new NotificationCompat.BigTextStyle().bigText(message));

        Uri sound = Uri.parse("android.resource://" + context.getPackageName()
                + "/" + soundFile);
        mBuilder.setSound(sound, 1);
        int mNotificationId = notifyId;
        NotificationManager mNotifyMgr = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = mBuilder.build();
        // notification.sound = sound;
        notification.flags |= Notification.DEFAULT_LIGHTS;
        notification.flags |= Notification.DEFAULT_VIBRATE;
        mNotifyMgr.notify(mNotificationId, notification);
    }

请告诉我一些解决方案,帮助有用的将是非常美联社preciated
谢谢!

Please advise me some solution, Useful helps will be highly appreciated Thanks!

推荐答案

确定添加此标志

notification.flags = Notification.FLAG_ONLY_ALERT_ONCE;

从谷歌文档 Googlde文档

这意味着

FLAG_ONLY_ALERT_ONCE:如果你想要的声音和/或振动每次发送通知的时间玩,即使尚未在此之前,取消它应该被设置

FLAG_ONLY_ALERT_ONCE : It should be set if you want the sound and/or vibration play each time the notification is sent, even if it has not been canceled before that.

这篇关于如何使游戏的自定义通知声音只有一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆