1

心拍をシミュレートするスマートウォッチ用のアプリを作成しようとしているので、1 秒から約 0.5 ~ 0.3 秒の間隔で、75 ミリ秒の間振動できる必要があります。

また、アプリがアンビエント モードになったとき、または完全なブラックスクリーンになり始めたときにも、これを行う必要があります。消費電力などは気にしません。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)ブラックスクリーンでも振動を送信できるようにしますが、結局のところ、アラームマネージャーのタイマーはそのような短い間隔に設定できませんか? 黒い画面、通常または周囲モードに関係なく、1秒以下と想定されているため、約5秒ごとに振動します...

コード:

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 を介してメッセージを絶えず送信し、それらを緊急に設定するとよいでしょうか?

4

1 に答える 1