What's wrong with my code - Notification - no sound no vibrate

陌路散爱 提交于 2019-12-03 07:22:31

This...

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

should be...

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

For all default values (Sound, Vibrate & Light) in 1 line of code you can use:

notification.defaults = Notification.DEFAULT_ALL;

this is the equivalent of

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

make sure you set permissions for vibrate in your Manifest

<uses-permission android:name="android.permission.VIBRATE" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!