android - 振动不适用于通知

标签 android android-notifications android-vibration

我正在尝试为通知设置振动和声音。出于某种原因,它对我不起作用:(这是我正在尝试的代码

NotificationManager notificationManager = getNotificationManager();
        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context);
        builder.setSound(alarmSound);
        builder.setVibrate(new long[] { 1000, 1000, 1000 });
        Notification notification = builder.setContentIntent(contentIntent)
                .setSmallIcon(icon).setTicker(title).setWhen(0)
                .setAutoCancel(true).setContentTitle(title).setPriority(Notification.PRIORITY_HIGH)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msgToDisply))
                .setContentText(msgToDisply).build();
        notificationManager.notify(NOTIFICATION, notification);
        stopSelf();

public NotificationManager getNotificationManager() {
        return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    }

我的 list 中有权限

<uses-permission android:name="android.permission.VIBRATE" />

有什么线索吗?

最佳答案

添加这个

notification.defaults|= Notification.DEFAULT_SOUND;
notification.defaults|= Notification.DEFAULT_LIGHTS;
notification.defaults|= Notification.DEFAULT_VIBRATE;

关于android - 振动不适用于通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27681342/

相关文章:

android facebook 喜欢

java - Android Lollipop 不显示键盘输入

android - android 中的 MyMapOverlay 类型未定义方法 getBaseContext()?为什么?

android - 停止应用程序从 fcm/gcm 获取通知

android - 获取以编程方式支持的通知振动模式列表

java - 如何在android中使用post数据调用webservice

Android - 替换已弃用的通知类

android - 升级到 Android 8.1 后 startForeground 失败

android - android启动应用程序主页时如何添加振动和铃声

android:如何通过开/关模式控制振动频率