我正在嘗試爲模擬您的心跳的智能手錶編寫應用程序,因此它需要能夠以1秒的時間間隔振動約0.5-0.3秒,持續一段時間75ms。頻繁使用環境/黑屏的可穿戴振動
它也需要這樣做,當應用程序進入環境模式或開始全黑屏。我不在乎電力消耗或其他什麼,它應該能夠運行像20-30分鐘,沒有別的。
在我正在開發的Moto360上,如果不將手錶保持在某個位置,環境模式會變成完全黑屏,並且只要進入黑屏,振動就會停止,所以除非有辦法阻止手錶進入黑屏,而我不知道這一點,否則我需要一種解決方案,它也適用於黑屏。
當只使用onEnterAmbient等事件時,手錶會因爲進入黑屏而沒有以正確的角度握住手錶而停止振動,並且振動並不總是一致的,因爲必須致電vibrator.vibrate()方法在輸入/更新時會再次出現,所以通常會導致振動模式中的小的不一致,這應該避免。因此,我認爲使用ambientmode的方法不起作用。
這裏是原代碼:
[...]
private long[] vibrationPattern_StandardPulse = {0, 75, 1000};
private long[] vibrationPattern_AcceleratedPulse = {0, 75, 600};
[...]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAmbientEnabled();
mContainerView = (BoxInsetLayout) findViewById(R.id.container);
vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
[...]
@Override
public void onEnterAmbient(Bundle ambientDetails) {
super.onEnterAmbient(ambientDetails);
keepVibrating();
}
@Override
public void onUpdateAmbient() {
super.onUpdateAmbient();
keepVibrating();
}
@Override
public void onExitAmbient() {
super.onExitAmbient();
keepVibrating();
[...]
public void keepVibrating() {
if (standardPulse) {
vibrator.vibrate(vibrationPattern_StandardPulse, 0);
} else {
vibrator.vibrate(vibrationPattern_AcceleratedPulse, 0);
}
}
[...]
所以我與alarmmanager又試了一次,(堅持此鏈接:https://developer.android.com/training/wearables/apps/always-on.html#UpdateContent),以便能夠在Blackscreen的時候,但事實證明也送振動,警報管理器的計時器不能設置爲如此小的時間間隔?它只振動每5秒左右,作爲應該1S少,無論在黑屏,或正常或環境模式是...
代碼:然後
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setAmbientEnabled();
mAmbientStateAlarmManager =
(AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent ambientStateIntent =
new Intent(getApplicationContext(), MainActivity.class);
mAmbientStatePendingIntent = PendingIntent.getActivity(
getApplicationContext(),
0,
ambientStateIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mContainerView = (BoxInsetLayout) findViewById(R.id.container);
//mClockView = (TextView) findViewById(R.id.clock);
vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
[...]}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
refreshDisplayAndSetNextUpdate();
}
private long AMBIENT_INTERVAL_MS = 0;
private void refreshDisplayAndSetNextUpdate() {
if (standardPulse) {
AMBIENT_INTERVAL_MS = 1000;
} else {
AMBIENT_INTERVAL_MS = 600;
}
if (isAmbient()) {
// Implement data retrieval and update the screen for ambient mode
vibrator.vibrate(75);
} else {
// Implement data retrieval and update the screen for interactive mode
vibrator.vibrate(75);
}
long timeMs = System.currentTimeMillis();
// Schedule a new alarm
if (isAmbient()) {
// Calculate the next trigger time
long triggerTimeMs = timeMs + AMBIENT_INTERVAL_MS;
mAmbientStateAlarmManager.setExact(
AlarmManager.RTC_WAKEUP,
triggerTimeMs,
mAmbientStatePendingIntent);
} else {
// Calculate the next trigger time for interactive mode
long triggerTimeMs = timeMs + AMBIENT_INTERVAL_MS;
mAmbientStateAlarmManager.setExact(
AlarmManager.RTC_WAKEUP,
triggerTimeMs,
mAmbientStatePendingIntent);
}
}
RefreshUpdateAndSetNextAlarm被稱爲也在onEnterAmbient事件等等,但並不像它應該的那樣工作。有沒有辦法在智能手錶上做這些事情,尤其是在Moto 360上?
也許如果我通過messageAPI不斷地從智能手機發送消息並將它們設置爲緊急?