Вызовы вибратора не заставляют часы вибрировать, пока часы находятся в режиме окружающего (?)

Я пытался написать простое приложение вибрации для своих часов Samsung Galaxy 4, но у меня возникла проблема. Часы не будут вибрировать, когда экран выключен. Он будет вибрировать только тогда, когда мое приложение открыто. Есть идеи, почему это так? Вот часть моего кода:

      // MainActivity
Intent i = new Intent(buttonView.getContext(), AlarmService.class);
startService(i);
      // AlarmService
Alarm alarm = new Alarm();
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
    alarm.setAlarm(this);
}
      // Alarm
public void setAlarm(Context context)
{
    AlarmManager am =( AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(context, Alarm.class);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
    long mills = getMillsForNextThirtySeconds();
    am.setExact(AlarmManager.RTC_WAKEUP, mills, pi);
}

@Override
public void onReceive(Context context, Intent intent)
{
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "szelag:test");

    wl.acquire();
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    VibrationEffect effect = VibrationEffect.createOneShot(1500, 255);
    
    // Watch never vibrates when it is in ambient(?) mode.
    vibrator.vibrate(effect);
    wl.release();
}

Спасибо!

1 ответ

См. документы здесь https://developer.android.com/reference/android/os/VibratorManager .

Приложение должно быть на переднем плане, чтобы сработала вибрация.

Может иметь отношение к вибрации Android Play от службы переднего плана

Другие вопросы по тегам