How can I request the vibrate permission?

后端 未结 2 625
挽巷
挽巷 2021-02-01 00:06

How can I request the vibrate permission in my Android application?

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 00:34

    Here is the link to the reference

    Add this to your manifest, as a direct child of the manifest element:

    
    

    This is how you let the phone Vibrate thru code:

    // Get instance of Vibrator from current Context
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    
    // Vibrate for 300 milliseconds
    v.vibrate(300);
    

    For a more creative pattern try the star wars theme =D

    v.vibrate(new long[]{0, 500, 110, 500, 110, 450, 110, 200, 110, 170, 40, 450, 110, 200, 110, 170, 40, 500}, -1);
    

提交回复
热议问题