데이터 저작자 표시

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

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

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

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

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

Kotlin

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

Java

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)
    }
}

Java

@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"

Java

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()

Java

// 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();

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