Reputation: 21452
I have utils class for vibration function its working in some apis but not working in another
api 17 is working
api 24 not working
could any one guide me why this code not working Note I took right permission
<uses-permission android:name="android.permission.VIBRATE" />
My Class
public class VibrateUtils {
public static void VibrateMethod(Context mContext , String PassedValue) {
// Get instance of Vibrator from current Context
Vibrator v = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
// Start without a delay
// Vibrate for 500 milliseconds
// Sleep for 1000 milliseconds
long[] pattern = {0, 500, 1000};
switch (PassedValue){
case "1":
// Start without a delay
// Vibrate for 500 milliseconds --> First time
// Sleep for 1000 milliseconds
pattern = new long[]{0, 500, 1000};
break;
case "2":
// Start without a delay
// Vibrate for 500 milliseconds --> First time
// Sleep for 1000 milliseconds
// Vibrate for 500 milliseconds --> Second time
// Sleep for 1000 milliseconds
pattern = new long[]{0, 500, 500 , 500 , 500 };
break;
case "3":
// Start without a delay
// Vibrate for 500 milliseconds --> First time
// Sleep for 1000 milliseconds
// Vibrate for 500 milliseconds --> Second time
// Sleep for 1000 milliseconds
// Vibrate for 500 milliseconds --> Third time
// Sleep for 1000 milliseconds
pattern = new long[]{0, 500, 1000 , 500 , 1000 , 500 , 1000};
break;
case "4":
// Start without a delay
// Vibrate for 500 milliseconds --> First time
// Sleep for 1000 milliseconds
// Vibrate for 500 milliseconds --> Second time
// Sleep for 1000 milliseconds
// Vibrate for 500 milliseconds --> Third time
// Sleep for 1000 milliseconds
// Vibrate for 500 milliseconds --> Fourth time
// Sleep for 1000 milliseconds
pattern = new long[]{0, 500, 1000 , 500 , 1000 , 500 , 1000 , 500 , 1000};
break;
}
// The '0' here means to repeat indefinitely
// '0' is actually the index at which the pattern keeps repeating from (the start)
// To repeat the pattern from any other point, you could increase the index, e.g. '1'
if(Build.VERSION.SDK_INT >= 26){
v.vibrate(VibrationEffect.createWaveform(pattern, VibrationEffect.DEFAULT_AMPLITUDE));
}else{
v.vibrate(pattern, -1);
}
}
}
Upvotes: 0
Views: 938
Reputation: 21452
Even the answer is not related to development but I would like answer my question , the reason why vibrate wastn't working that the vibration intensity for Notification was off
Reference https://android.stackexchange.com/a/158261
Upvotes: 2