当手表处于环境(?)模式时,振动器调用不会导致手表振动

Vibrator calls not causing watch to vibrate while watch is in ambient(?) mode

我一直在尝试为我的 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();
}

谢谢!

在此处查看文档 https://developer.android.com/reference/android/os/VibratorManager

The app should be in foreground for the vibration to happen.

可能相关