What I am doing:
I am making one app using Android Beacon library. I am using RegionBootstrap
for implementation of foreground ranging and transmission of Altbeacons.
What I want:
I want to make the phone vibrate for suppose 500 ms when I can find a beacon within certain meters of range even when my app is running as foreground service.
Logic:
Logic is simple, I am performing scanning at a specific interval. Suppose I found beacons A, B, C with distance 1m, 1.5m, 0.6m. Now my threshold distance is 0.8m so I will make the phone vibrate as long as the above condition satisfies, that means user has to go out to make the distance larger so as to stop vibration.
Code I used:
I have found one code snippet to make the vibration
import android.os.Vibrator;
...
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
//deprecated in API 26
v.vibrate(500);
}
Issue I am facing:
This works perfectly when my app is open. Once I close the app and the foreground service keeps scanning and transmitting, the vibration doesn't occur.
I am new to android development, kindly help me to resolve this issue.