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

前端 未结 2 1684
情话喂你
情话喂你 2021-02-08 12:24

I seem to have a problem with my code. I have created a test activity, just to see what\'s wrong, still I can\'t.

public class test extends Activity {
/** Called         


        
相关标签:
2条回答
  • 2021-02-08 12:46

    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;
    
    0 讨论(0)
  • 2021-02-08 13:01

    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" />
    
    0 讨论(0)
提交回复
热议问题