Android Native Devlopment
I try to create custom vibration of incoming call:
I am running a foreground service to avoid the user from setting phone state to vibration in order to take control of the Vibrator during incoming call but it failed.
public class CallsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
AudioManager am = (AudioManager) context.getSystemService(context.AUDIO_SERVICE);
long[] VIBRATE_PATTERN = {500,500,500,500,500,500,500,500};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// API 26 and above
mVibrator.vibrate(VibrationEffect.createWaveform(VIBRATE_PATTERN,-1));
} else {
// Below API 26
mVibrator.vibrate(VIBRATE_PATTERN, -1);
}
}
}
}
I have already tried to run the vibration in new thread and run it from service but no success. I did a research and I realized that on new android api levels, the code in broadcast receiver runs with low priority so I tried to run a schedule job -> service with higher priority and I got the same result.
there are few time that a little short vibrate starts but it stops after that