Enabling and disabling vibration in android programmatically

前端 未结 4 1770
攒了一身酷
攒了一身酷 2020-12-10 15:52

In one of my android apps, I need to enable or disable the vibration completely irrespective of the mode (i.e. silent or general or loud).

I am currently using the f

4条回答
  •  情话喂你
    2020-12-10 16:12

    Check this, i found that as the first google result. The code:

    if(isVibrate){
    Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);  
         vib.vibrate(500);
          Toast.makeText(this, "vib started", Toast.LENGTH_LONG).show();
    }
    
    else{
    
    // do nothing
    
    }
    

提交回复
热议问题