데이터 기여 분석

Google 피트니스의 모든 데이터 포인트에는 연결된 데이터 소스가 있습니다. 데이터 소스에는 데이터를 수집하거나 변환하는 앱 또는 기기를 식별하는 정보가 포함됩니다. 앱의 패키지 이름은 실제 센서를 나타내지 않는 데이터 소스에 사용할 수 있습니다.

Google 피트니스를 사용하면 다음 작업을 할 수 있습니다.

  • 특정 앱과 연결된 데이터를 보기 위한 인텐트를 호출합니다.
  • 앱을 사용하여 데이터를 표시하는 인텐트를 수신합니다.
  • 세션이 삽입된 앱을 확인합니다. 자세한 내용은 세션 사용을 참고하세요.

데이터 포인트를 삽입한 앱 확인

데이터 포인트를 삽입한 애플리케이션의 패키지 이름을 가져오려면 먼저 DataPoint.getOriginalDataSource을 호출하여 데이터 소스를 가져온 다음 DataSource.getAppPackageName 메서드를 호출합니다.

Kotlin

val dataPoint : DataPoint = ...
val dataSource = dataPoint.originalDataSource
val appPkgName = dataSource.appPackageName

자바

DataPoint dataPoint = ...
DataSource dataSource = dataPoint.getOriginalDataSource();
String appPkgName = dataSource.getAppPackageName();

다른 앱에서 인텐트 수신

다른 건강 및 웰빙 앱에서 인텐트를 수신하도록 앱을 등록하려면 매니페스트에서 다음과 유사한 인텐트 필터를 선언합니다.

<intent-filter>
    <action android:name="vnd.google.fitness.VIEW" />
    <data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.cumulative" />
    <data android:mimeType="vnd.google.fitness.data_type/com.google.step_count.delta" />
</intent-filter>

앱이 Google 피트니스에서 수신하는 각 인텐트는 한 가지 유형이지만 단일 인텐트 필터에서 여러 MIME 유형을 필터링할 수 있습니다. 앱의 인텐트 필터에는 맞춤 데이터 유형을 포함하여 앱에서 지원하는 모든 데이터 유형이 포함되어야 합니다.

피트니스 인텐트에는 다음 추가 항목이 포함됩니다.

  • vnd.google.gms.fitness.start_time
  • vnd.google.gms.fitness.end_time
  • vnd.google.gms.fitness.data_source

이러한 추가 데이터에서 다음과 같은 데이터를 얻을 수 있습니다.

Kotlin

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    ...
    val supportedType = DataType.getMimeType(DataType.TYPE_STEP_COUNT_DELTA)

    if (Intent.ACTION_VIEW == intent.action && supportedType == intent.type) {
        // Get the intent extras
        val startTime = Fitness.getStartTime(intent, TimeUnit.MILLISECONDS);
        val endTime = Fitness.getEndTime(intent, TimeUnit.MILLISECONDS)
        val dataSource = DataSource.extract(intent)
    }
}

자바

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    String supportedType = DataType.getMimeType(DataType.TYPE_STEP_COUNT_DELTA);

    if (Intent.ACTION_VIEW.equals(getIntent().getAction()) && supportedType.equals(getIntent().getType())
    {
        // Get the intent extras
        long startTime = Fitness.getStartTime(getIntent(), TimeUnit.MILLISECONDS);
        long endTime = Fitness.getEndTime(getIntent(), TimeUnit.MILLISECONDS);
        DataSource dataSource = DataSource.extract(getIntent());
    }
}

맞춤 데이터 유형의 MIME 유형을 가져오려면 MIME_TYPE_PREFIX 상수를 사용하세요.

Kotlin

val supportedType = DataType.MIME_TYPE_PREFIX + "com.company.customdatatype"

자바

String supportedType = DataType.MIME_TYPE_PREFIX + "com.company.customdatatype";

인텐트를 호출하여 데이터 보기

다른 앱과 함께 데이터를 보기 위해 인텐트를 호출하려면 HistoryApi.ViewIntentBuilder 클래스를 사용합니다.

Kotlin

// Inside your activity
val startTime = ...
val endTime = ...
val dataSource = ...
val dataType = ...

val fitIntent = HistoryApi.ViewIntentBuilder(this, dataType)
    .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
    .setDataSource(dataSource) // Optional if a specific data source is desired
    .setPreferredApplication("com.example.app") // Optional if you'd like a
    // specific app to handle the intent if that app is installed on the device
    .build()

자바

// Inside your activity
long startTime = ...
long endTime = ...
DataSource dataSource = ...
DataType dataType = ...

Intent fitIntent = new HistoryApi.ViewIntentBuilder(this, dataType)
    .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
    .setDataSource(dataSource) // Optional if a specific data source is desired
    .setPreferredApplication("com.example.app") // Optional if you'd like a
    // specific app to handle the intent if that app is installed on the device
    .build();

인텐트 및 인텐트 필터 사용 방법 자세히 알아보기