コード例 #1
0
  private void registerIntent() {

    if (mRecognitionPendingIntent == null) {
      Intent intent = new Intent(mApplicationContext, SKActivityRecognitionIntentService.class);
      mRecognitionPendingIntent =
          PendingIntent.getService(
              mApplicationContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    mActivityRecognition.requestActivityUpdates(mClient, 0, mRecognitionPendingIntent);
  }
コード例 #2
0
  private void unregisterIntent() {

    mActivityRecognition.removeActivityUpdates(mClient, mRecognitionPendingIntent);
    mRecognitionPendingIntent.cancel();
    mRecognitionPendingIntent = null;
  }